Fire event from one object to notify end of frame

2019-08-24 15:22发布

I am relatively new to AS and want to know how I can notify that an object I imported has reached it's final frame. Basically I want to create a .fla with a class file maybe and import the .swf as a movieclip in an other fla and maybe have multiple instances of that imported movieclip. Now I would like to know how I can get notified that one instance of the imported movieclip has reached the final frame.

Thank you

2条回答
走好不送
2楼-- · 2019-08-24 16:07

You can use MovieClip' undocumented addFrameScript() method , like:

mc.addFrameScript( mc.totalFrames - 1 , lastFrameHandler);

function lastFrameHandler():void{
    //
    // mc.stop();
    //
}

With addFrameScript you don't need to put any code in .fla' frames/timeline!

查看更多
来,给爷笑一个
3楼-- · 2019-08-24 16:10

You can fire event with dispatchEvent(new Event("eventname")). Write dispatchEvent on end of frame.

dispatchEvent(new Event(Event.COMPLETE));

and, listen for the event:

mc.addEventListener(Event.COMPLETE, endOfFrameHandler);
function endOfFrameHandler(e:Event):void 
{
    ...
}
查看更多
登录 后发表回答