Nobien A nerd blog about nerdy things by … nerdy guys?

5Feb/095

AS3: Stopping All Timeline Animations

I haven't posted in months for good reason. I've been involved in a pretty large project at Almighty that led to many late nights. All in all though, the end product turned out to be pretty awesome. I'll post something more on it later. Until then, I hope to roll out some snippets of code that I found useful during the project.

The following snippet of code is a recursive loop that halts all timeline-based animations (assuming they're on a gotoAndStop() loop. This came in handy when working with animation designers.

function haltAllAnimations( mc:MovieClip = null ):void
{
    if( !mc ) mc = this as MovieClip;
 
    for(var i:int = 0; i < mc.numChildren ; i++)
    {
         if( (mc.getChildAt( i ) is MovieClip) == false ) continue;
 
        MovieClip( mc.getChildAt( i ) ).stop();
        if( mc.numChildren > 0 )
            haltAllAnimations( MovieClip( mc.getChildAt( i ) ) );
    }
}