如何访问儿童儿童递归? [英] How to access children of children recursively?

查看:115
本文介绍了如何访问儿童儿童递归?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个帆布它也有它里面的那些许多组件,里面有他们的许多组件。

的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.

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));
        }
    }
}

}

这篇关于如何访问儿童儿童递归?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆