define('DISALLOW_FILE_EDIT', true); Flash – Page 2 – unFocus Projects – Kevin Newman and Ken Newman

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:

[cc lang=’actionscript3′]
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(); } } } } [/cc] 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.