Stop All Child MovieClips in Flash with Actionscript 3.0

While trying to come up with a way to get two different movies loaded at the same time, to play at different frame rates, I came up with a method to recursively stop all child movies of an as3 MovieClip. I didn’t end up using it, but I thought it might be useful for someone, so here it is:

import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;

function stopAll(content:DisplayObjectContainer):void
{
    if (content is MovieClip)
        (content as MovieClip).stop();
   
    if (content.numChildren)
    {
        var child:DisplayObjectContainer;
        for (var i:int, n:int = content.numChildren; i < n; ++i)
        {
            if (content.getChildAt(i) is DisplayObjectContainer)
            {
                child = content.getChildAt(i) as DisplayObjectContainer;
               
                if (child.numChildren)
                    stopAll(child);
                else if (child is MovieClip)
                    (child as MovieClip).stop();
            }
        }
    }
}

The plan was to use that to stop playing movies, every other frame, and restart them on the alternative frames, but there is apparently no way to tell if a MovieClip is currently playing or not, to know which ones to restart.

I did end up hacking Tweener to add support for a Timer based update method. That way I can adjust the stage FPS to match the older timeline content (at 12fps) and have my Tweener based interactions work at a silky smooth 60 FPS.

I’ll post more on that later.

This entry was posted in Tips & Tricks and tagged , , by Kevin Newman. Bookmark the permalink.

About Kevin Newman

I'm the lead developer at adcSTUDIO located in Kingston NY (in Livingston Manor NY before that). I do all kinds of things there, from robust server side work to the much more enjoyable client side development in HTML/JavaScript/Flash (RIAs, HTML5, etc.) and all the other tech-buzz-phrases of the moment. My brother came up with the idea for unFocus.com which was originally meant be a place to discuss and blog about whatever topics we both found interesting, from politics to technology, to art and design. Time was scarce, and I need a place to host History Keeper, and unFocus Projects - a sub focus of unfocus.com was born, and eventually migrated to the font page. Oh, and I'm on Twitter (@Touvan) and Google+.