简体   繁体   English

如何使用as3同时访问所有动画片段(以及动画片段中的动画片段,......)?

[英]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. 我正在使用Adobe Animate(或Adobe Flash Professional),我经常使用as3导航时间轴。 I want to reset all movieclips (and movieclips inside a moviclip) when the stage reach to an exact frame. 我想在舞台到达精确帧时重置所有动画片段(以及moviclip中的动画片段)。 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? 有没有办法做到这一点?

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: 如果要重置当前附加到舞台的所有MovieClip实例,请执行以下操作:

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM