[英]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. 首先,我试图重现您的问题。
TestClass
. TestClass
添加了四个子MovieClips。 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.