简体   繁体   English

AS3在库中获得了movieclip的子代

[英]AS3 get children of movieclip in library

So I have this movievlip in my library, which is an instance of TestClass . 所以我的库中有这个movievlip,它是TestClass一个实例。 There are four other movieclips in the parent movieclip. 父动画片段中还有其他四个动画片段。 This is TestClass : 这是TestClass

package  {
    import flash.display.MovieClip;

    public class TestClass extends MovieClip{

        public function TestClass() {
            for(var i:int = 0; i < numChildren; i++){
                trace(getChildAt(i));
            }
        }
    }   
}

However, this traces null four times, while it should trace [object MovieClip] right? 但是,此跟踪为null四次,而它应该跟踪[object MovieClip]对吗? Also, when I set the names of the movieclips under the accessibility tab and then use getChildByName('test') , it still traces null . 另外,当我在辅助功能选项卡下设置影片剪辑的名称,然后使用getChildByName('test') ,它仍会跟踪null

My question is: how can I get specific children from a movieclip in my library? 我的问题是:如何从图书馆的短片中找到特定的孩子? For instance, when there are two children, I only want to get the child with the name test 例如,当有两个孩子时,我只想让孩子的名字叫test

Firstly, I tried to reproduce your issue. 首先,我试图重现您的问题。

  1. I created a parent MovieClip and set a linkage name as "TestClass". 我创建了一个父MovieClip,并将链接名称设置为“ TestClass”。 Also, I added four child MovieClips to the TestClass . 另外,我在TestClass添加了四个子MovieClips。

在此处输入图片说明

  1. I created TestClass.as file with the same code. 我使用相同的代码创建了TestClass.as文件。

In the output tab I see four [object MovieClip] lines. 在输出选项卡中,我看到四行[object MovieClip] I don't know why you got null . 我不知道你为什么null Can you provide FLA file? 可以提供FLA文件吗?


Why you set a name of child in the accessibility tab? 为什么在辅助功能选项卡中设置孩子的名字? You should set name in the "instance name" of properties panel. 您应该在属性面板的“实例名称”中设置名称。

在此处输入图片说明

So you can address to child by its name: child_1 in my case. 因此,您可以通过其名称为child寻址:在本例中为child_1 trace(child_1); returns [object MovieClip] . 返回[object MovieClip]

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

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