【问题标题】:How to access all movieclips (and movieclips inside a movieclips,...) at a sametime with as3?如何使用 as3 同时访问所有影片剪辑(以及影片剪辑中的影片剪辑......)?
【发布时间】:2017-06-24 04:18:26
【问题描述】:

我使用的是 Adob​​e Animate(或 Adob​​e Flash Professional),我经常使用 as3 浏览时间线。 当舞台达到精确帧时,我想重置所有影片剪辑(以及影片剪辑中的影片剪辑)。 喜欢:

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

我正在考虑访问库中的所有影片剪辑,但我不知道如何。 有什么办法吗?

【问题讨论】:

    标签: actionscript-3 flash adobe movieclip multipleselection


    【解决方案1】:

    您无法访问库中的内容,因为库是一个设计时概念。如果要重置当前附加到舞台的所有 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);
    }
    

    【讨论】:

    • ummmm - 只要为项目提供链接,您就可以在运行时访问库。 stackoverflow.com/questions/22940461/… 但我仍然会为此 +1,因为这种递归算法确实可以解决问题。
    • @Zze,恕我直言,Library 是原型的调色板,您无法访问其内容运行时。只要它们链接到 AS3 类,您就可以使用“new”运算符来实例化它们,但这就是它的范围。您不能从库中删除项目,也不能修改它们。更糟糕的是,除非您知道相应的 AS3 类,否则您甚至无法列出链接的类。
    • 没错,但我只是说您可以访问该库。您可以从中实例化。我没有说明列出的任何其他功能。我只是认为“您无法访问图书馆中的东西”是不正确的-正如您在上面所说的那样。应该是“你不能在图书馆里操纵东西”。不是说图书馆低于平均水平 - 哈哈
    猜你喜欢
    • 1970-01-01
    • 2011-08-10
    • 2017-08-23
    • 1970-01-01
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 1970-01-01
    • 2014-08-28
    相关资源
    最近更新 更多