Controlling the animation of nested MovieClips

I have seen this issue pop up several times recently, so I decided to dedicate a post to it.

Here’s the situation: you have a complex hierarchy consisting of a number of animated MovieClips, nested into one another at various levels. You’d like to be able to start and stop the animation of the whole hierarchy (think of a “pause” functionality in a game for example), but the standard stop / play methods of the MovieClip class just aren’t going to cut it, as they only apply to the top-level timeline. Now what?

Well, I made a little class called AnimationControl, which recursively crawls the entire hierarchy, and stops / plays every element within.
Playing around with the demonstration SWF below will make this whole concept a lot clearer than extra paragraphs of text could, so go ahead and click away:

[kml_flashembed movie="" width="550" height="420" menu="false" wmode="opaque" fversion="10" useexpressinstall="true" /]

...and now for the code.

Just import the AnimationControl class, and call the static methods using something like AnimationControl.playAll(yourobjectname);.
It's pretty robust - at least it certainly won't freak out if you try to use it on weird object-types with no timeline.

Also, since the function-names to call (stop and play by default) can be explicitly specified, adding more elaborate functionality (like gotoAndStop ("yourlabelname");) should be a fairly trivial change.

One Response to Controlling the animation of nested MovieClips

Leave Your Mark

Recent Posts