numChildren
和getChildAt
在AS3中的主要用途是什么?
请用一个简单的例子来帮助我。
发布于 2014-12-23 06:50:21
假设我们有一个电影中的' mcA ' mcA包含了另外3个movieclip 'mcB'、'mcC'、‘mcD’。现在,我们可以说mcBE 29
、E 110
mcCE 211和e 112
mcDE 213/code>都是E 114mcA
E 215所以如果我们想知道有多少智利的话,我们可以使用它。就我们而言,我们有:
mcA.numChildren -> this is equals to 3
trace(mcA.numChildren); //output 3
trace(mcB.numChildren); //output 0
getChildAt是一个metod/函数,它有一个参数,指示子层的索引/层。如果存在图层,此方法将在该索引处返回子节点。
例如:
mcA :
index0- mcC
index1 - mcD
index2 - mcB
如果这是mcA的结构,那么:
mcA.getChildAt(0); //this will return mcC
mcA.getChildAt(1); //this will return mcD
mcA.getChildAt(2); //this will return mcB
mcA.getChildAt(3); //this is error 'The supplied index is out of bounds ...'
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#getChildAt()(http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#getChildAt(%29);
https://stackoverflow.com/questions/27615030
复制相似问题