package
{
import flash.display.*;
public class documentclass extends MovieClip
{
public var playscreen:avoiderclass;
public function documentclass()
{
playscreen.addEventListener(playerEvent.DEAD, onplayerdeath);
playscreen.x = 0;
playscreen.y = 0;
playscreen = new avoiderclass();
addChild(playscreen);
}
public function onplayerdeath(PlayerEvent:playerEvent):void
{
var Gameover:gameover = new gameover();
Gameover.x = 0;
Gameover.y = 0;
addChild(Gameover);
playscreen = null;
}
}
}
好吧,当舞台(这个类)是将玩家和敌人的动画片夹入其中的阶段时,它起作用了。然后我为舞台添加了这个,并为剧本制作了另一个... 我不知道为什么它不起作用,但任何人都可以给我任何可能的原因,不会出现错误......
答案 0 :(得分:0)
您必须将变量playcreen设置为新的avoiderclass对象,如下所示:
playscreen = new avoiderclass();
之前......
playscreen.addEventListener(playerEvent.DEAD, onplayerdeath);
playscreen.x = 0;
playscreen.y = 0;
请尝试这种方式。
public class documentclass extends MovieClip {
public var playscreen:avoiderclass;
public function documentclass(){
// construct the object first
playscreen = new avoiderclass();
// then manipulate it.
playscreen.addEventListener(playerEvent.DEAD, onplayerdeath);
playscreen.x = 0;
playscreen.y = 0;
addChild(playscreen);
}
在这个函数中,不要忘记从displaylist中删除playcreen
public function onplayerdeath(PlayerEvent:playerEvent):void {
var Gameover:gameover = new gameover();
Gameover.x = 0;
Gameover.y = 0;
addChild(Gameover);
// first remove the playscreen from display list
removeChild(playscreen);
// then set it to null, now really unreachable and eligible for gc
playscreen = null;
}
}
}