AS3 - 特定帧事件监听器?

时间:2012-08-29 14:51:37

标签: actionscript-3 events

我有以下代码来生成新的爆炸影片剪辑。不幸的是,GameEvent.EXPLOSION_FINISHED事件永远不会被触发。每个帧都有一个特殊的事件监听器吗?

var exp:Explosion = new Explosion();
exp.addFrameScript(exp.totalFrames - 1, function():void {exp.stop();dispatchEvent( new GameEvent( GameEvent.EXPLOSION_FINISHED));});
exp.addEventListener(GameEvent.EXPLOSION_FINISHED, tidyUp, false, 0, true);

2 个答案:

答案 0 :(得分:1)

我认为你的问题是你没有在exp对象上调度事件,而是你的代码块所在的对象。试试这个:

exp.addFrameScript(exp.totalFrames - 1, function():void {exp.stop();exp.dispatchEvent( new GameEvent( GameEvent.EXPLOSION_FINISHED));});

答案 1 :(得分:0)

stage.addEventListener(GameEvent.EXPLOSION_FINISHED,tidyUp);
...
function tidyUp(e:Event):void {
    var s:Object=e.target;
    if (s is Explosion) {
        var expl:Explosion=s as Explosion;
        // process your "expl" Explosion object here
    }
}

应该这样做。