first class
package {
import net.flashpunk.FP;
import net.flashpunk.Entity;
import net.flashpunk.graphics.Image;
public class MyLoot extends Entity {
[Embed(source='assets/wall.png')]
private const LOOT:Class;
FP.console.enable();
public var n:Boolean = false;
public function MyLoot(posX:int, posY:int){
graphic = new Image(LOOT);
setHitbox(46, 46);
type = "loot";
x = posX * 46;
y = posY * 46;
}
override public function update():void {
for (var i:int = 0; i < n; i++){ // Why this cycle does not start
if (destroy()){
var aa:MyWorld = new MyWorld();
aa.nn();
}else {
n = false;
break;
}
}
}
public function destroy():void{ // this function working
FP.world.remove(this);
n = true;
trace(n);
}
}
}
second class
package {
import net.flashpunk.World;
public class MyWorld extends World {
public function MyWorld() {
add(new MyPlayer(3, 8));
add(new MyStone(3, 4));
add(new MyLoot(5, 10));
add(new MyRestart(10, 0));
for (var i:int = 0; i < 13; i++){
add(new MyWall(i, 1));
add(new MyWall(i, 13));
}
for (i = 1; i < 13; i++){
add(new MyWall(0, i));
add(new MyWall(12, i));
}
for (i = 2; i < 11; i++){
add(new MyWall(9, i));
}
for (i = 5; i < 13; i++){
add(new MyWall(7, i));
}
}
public function nn():void{
add(new MyLoot(5, 11));
}
}
}