views:

32

answers:

2

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
+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
nice hack. More elegant than my answer.
Allan
Awesome. I wonder why the 'addFrameScript' method isn't documented in the as3 reference?
Vaselinessa
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