How do I know when MovieClip placed on stage to finish play?

牧云@^-^@ 提交于 2019-12-08 01:50:43

问题


MovieClip(mcName).play();
MovieClip(mcName).addEventListener(??????, myStopFunction);

Or how differently you can learn about the end of play?

MovieClip is an external file and loaded into the swf as needed.


回答1:


Use two properties all MovieClips have:

totalFrames - currentFrame

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/MovieClip.html#currentFrame

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/MovieClip.html#totalFrames




回答2:


When I have a custom animation and want to know when finishes I use to dispatch a custom event from the last frame of the animation. Usually an Event.COMPLETE will do.

In the last frame of the myAnimation MovieClip I do:

this.dispatchEvent(new Event(Event.COMPLETE));
stop();

Then in the main code I listen add listener to that evnet:

myAnimation.addEventListener(Event.COMPLETE, animationEndHandler);



回答3:


Almost like @daniel.sedlacek answer, but without timeline code :

var mc : MovieClip = new $TestMovieClip();          
mc.addEventListener(Event.COMPLETE, function() : void {
    trace("COMPLETE");
});
mc.addFrameScript(mc.totalFrames-1, function() : void {
    mc.dispatchEvent(new Event(Event.COMPLETE));                
});
mc.play();



回答4:


Only check currentFrame and totalFrames is not enough for a MovieClip that has multiple scenes. You must also check if it is at the last scene.

function isAtLastFrame(mc:MovieClip):Boolean
{
  return currentScene.name == mc.scenes[mc.scenes.length - 1].name && currentFrame == currentScene.numFrames;
}


来源:https://stackoverflow.com/questions/4121495/how-do-i-know-when-movieclip-placed-on-stage-to-finish-play

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