Start/stop all nested MovieClips

Animation takes CPU time and sometimes it’s useful to stop/play it. The problem is that MovieClip’s in animation can be hardly nested.

Solution

Stop/start MovieClips recursively:

  1. public static function massStop(target:DisplayObjectContainer,
  2.     frame:Object = 1):void
  3. {
  4.     if (target is MovieClip)
  5.         MovieClip(target).gotoAndStop(frame);
  6.     var n:int = target.numChildren;
  7.     for (var i:int = 0; i < n; i++)
  8.     {
  9.         var child:DisplayObjectContainer = target.getChildAt(i)
  10.             as DisplayObjectContainer;
  11.         if (child)
  12.             massStop(child, frame);
  13.     }
  14. }
  15.  
  16. public static function massPlay(target:DisplayObjectContainer):void
  17. {
  18.     if (target is MovieClip)
  19.         MovieClip(target).play();
  20.     var n:int = target.numChildren;
  21.     for (var i:int = 0; i < n; i++)
  22.     {
  23.         var child:DisplayObjectContainer = target.getChildAt(i)
  24.             as DisplayObjectContainer;
  25.         if (child)
  26.             massPlay(child);
  27.     }
  28. }

2 responses to “Start/stop all nested MovieClips”

  1. Hello sir,

    last two days i am trying to find solution for script problem. i create move. that content lots of nested movie clips. i have created menu bar that control all movies play & stop. also pause all movies. but prob. is when i pause main timeline movie it is paused with sound & frame animation. but not stopped nested movie clips which i made in classic tween animation.so i need help to get solution. i am new in scripting. i used AS2 in my movie.

    so please give me a solution.
    Thanks

Leave a Reply