在ActionScript 3中,如果我遍历影片剪辑的子级,它将返回DisplayObjectContainer,它是DisplayObject的列表。
但是,AS3 typeof无法识别MovieClip,因为MovieClip现在是对象,而不是数据类型。如何正确识别MovieClip?
我在网上找到3个解决方案:
解决方案1(我正在使用的解决方案):
First set the MovieClip name to a specific name, then in the iterate process, check the name of children using child.name.indexOf("specificName") > -1
解决方案2:
use child.hasOwnProperty("numChildren") to identify a MovieClip
解决方案3:
use 3rd party plug-in like FlashDevelop
哪种解决方案是最好的?还是有其他选择?
最佳答案
实际上,它在AS3中得到了很大的改进和简化。您可以简单地使用“is”运算符:
for(var i:int = 0; i < containerObj.numChildren; i++) {
if(containerObj.getChildAt(i) is MovieClip) {
// do something
}
}
Flash livedocs for this topic有更多详细信息。
关于flash - 在AS3中识别DisplayObjectContainer中的MovieClip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1647674/