Search code examples
actionscript-3flashadobemovieclipmultipleselection

How to access all movieclips (and movieclips inside a movieclips,...) at a sametime with as3?


I am using Adobe Animate (or Adobe Flash Professional) and I often navigate timeline with as3. I want to reset all movieclips (and movieclips inside a moviclip) when the stage reach to an exact frame. like:

 if (this.currentFrame == 120) 
    { 
        allMovieClips.gotoAndPlay(1);
    } 

I am thinking about taking access to all movieclips in library but I don't know how. Is there any way to do that?


Solution

  • You cannot access things in Library as the Library is a design-time concept. If you want to reset all the MovieClip instances presently attached to the Stage, you do the following:

    import flash.display.Sprite;
    import flash.display.MovieClip;
    
    // Start resetting them from the topmost timeline.
    reset(root as Sprite);
    
    function reset(target:Sprite):void
    {
        // First, browse all the children of the target.
        for (var i:int = 0; i < target.numChildren; i++)
        {
            var aChild:Sprite = target.getChildAt(i) as Sprite;
    
            // If a child is a container then go recursive on it.
            if (aChild) reset(aChild);
        }
    
        // Second, if the target is not only the container
        // of other things but a MovieClip itself then rewind it.
        if  (target is MovieClip)
            (target as MovieClip).gotoAndPlay(1);
    }