I want to execute a function upon completion of a MovieClip's animation. That is, I would command it to play() or gotoAndPlay(). I don't know of any listener that I can attach to the MovieClip with the "addEventListener()" command. Have any idea I can do?
A:
stage.addEventListener(Event.ENTER_FRAME, onCheckAnimationComplete)
function onCheckAnimationComplete(e:Event)
{
if(animation.currentFrame==animation.totalFrames)
{
//TODO call a function
}
}
Allan
2010-07-29 22:50:58
+2
A:
You can use the addFrameScript method, as shown in this post to dispatch a custom event when the last frame is reached.
TandemAdam
2010-07-30 01:12:50
nice hack. More elegant than my answer.
Allan
2010-07-30 02:32:24
Awesome. I wonder why the 'addFrameScript' method isn't documented in the as3 reference?
Vaselinessa
2010-08-03 16:17:14
I don't think it is recommended by Adobe, but apparently it's what they use internally. But there is nowhere saying NOT to use it! Often languages have undocumented APIs ie Apple's iPhone framework.
TandemAdam
2010-08-03 20:14:01