Fire event from one object to notify end of frame

筅森魡賤 提交于 2019-12-13 04:47:28

问题


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


回答1:


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 
{
    ...
}



回答2:


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!



来源:https://stackoverflow.com/questions/19722342/fire-event-from-one-object-to-notify-end-of-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!