由网友(梦想、编织着青春)分享简介:我有一个帆布它也有它里面的那些许多组件,里面有他们的许多组件。 的getChildren()只返回顶级儿童。这是检索所有的儿童(儿童的儿童的儿童等)的最佳方式。 嗯,我八九不离十知道如何通过迭代的孩子要做到这一点,但code是非常的混乱。我想preFER用一个漂亮的递归函数。有没有人写的吗?还是有一个的Util类来做到...![做瑜伽的小孩子插画AI素材免费下载 红动网](https://p.xsw88.cn/allimgs/daicuo/20230908/512.png)
我有一个帆布它也有它里面的那些许多组件,里面有他们的许多组件。
的getChildren()只返回顶级儿童。这是检索所有的儿童(儿童的儿童的儿童等)的最佳方式。
嗯,我八九不离十知道如何通过迭代的孩子要做到这一点,但code是非常的混乱。我想preFER用一个漂亮的递归函数。有没有人写的吗?还是有一个的Util类来做到这一点?
解决方案 私有函数回避(显示:级DisplayObjectContainer):无效{
如果(显示器){
对于(VAR我:= 0; I< _display.numChildren;我++){
VAR孩子:的DisplayObject = display.getChildAt(我);
跟踪(child.name);
如果(孩子的DisplayObjectContainer){
回避(级DisplayObjectContainer(子));
}
}
}
}
I have a Canvas which has many components inside it and those again, have many components inside them.
![做瑜伽的小孩子插画AI素材免费下载 红动网](https://p.xsw88.cn/allimgs/daicuo/20230908/512.png)
getChildren() returns only the top level children. What is the best way to retrieve all the children (children of children of children and so on).
Well, I sorta know how to do this by iterating through the children, but the code is really messy. I'd prefer to use a nice recursive function. Has anyone written this before? Or is there a Util class to do this?
解决方案private function recuse(display : DisplayObjectContainer) : void {
if(display) {
for (var i : int = 0;i < _display.numChildren;i++) {
var child : DisplayObject = display.getChildAt(i);
trace(child.name);
if(child is DisplayObjectContainer) {
recuse(DisplayObjectContainer(child));
}
}
}
}
相关推荐
最新文章