0
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;
        }
    }

}

好的,当舞台(这个类)是将玩家和敌人的电影剪辑拉入其中的类时,它起作用了。然后我为舞台添加了这个并将另一个用于播放屏幕......我不知道为什么它不起作用,但谁能给我任何可能为什么它不起作用,没有错误弹出......

4

1 回答 1

0

您必须将变量 playscreen 设置为一个新的避免类对象,如下所示:

        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);
    }

在该功能中,不要忘记从显示列表中删除播放屏幕

    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;
    }
  }
}
于 2013-04-05T21:42:51.467 回答