1

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?

1 Answers1

3

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);
}
Organis
  • 7,243
  • 2
  • 12
  • 14
  • ummmm - you can access the library at run time as long as the item is given a linkage. http://stackoverflow.com/questions/22940461/loading-and-unloading-content-from-library-in-as3 but I am still going to +1 this because this recursive algorithm will indeed solve the issue. – Zze Feb 07 '17 at 09:44
  • @Zze, with all due respect, Library is a palette of prototypes and you cannot access its content runtime. You can instantiate things with "new" operator as long as they's linked to AS3 classes but that's the extent of it. You cannot remove items from Library, you cannot modify them. Worse, you cannot even list the linked ones unless you know the respective AS3 classes. – Organis Feb 07 '17 at 10:44
  • That is correct, however all I said was that you can **access** the library. You can instantiate from it. I didn't state any other functionality listed. I just think that "You cannot access thing in Library" is incorrect - as you just stated above. It should be maybe "you cannot manipulate things in Library". Not arguing that the Library is sub average - haha – Zze Feb 07 '17 at 11:00