通过每一个组件实例递归迭代 [英] Recursive iteration through every component instance
本文介绍了通过每一个组件实例递归迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的Flex应用程序不同的自定义组件实例。我要循环通过他们递归,并得到他们的实例ID。递归部分对我来说很重要。 谁能告诉我什么是做到这一点的最好方法是什么? 我曾尝试这样做,但它没有这样做递归的:
每个(VAR myItem:*在this.MasterContainer.childDescriptors)
{
跟踪(myItem.id);
}
解决方案
这将做到这一点:
私有函数findControlsRecursive(电流的DisplayObjectContainer,控制:ArrayCollection的):无效
{
对于(VAR IDX:= 0; IDX< current.numChildren; IDX ++)
{
VAR孩子:的DisplayObject = current.getChildAt(IDX);
controls.addItem(child.name);
VAR childContainer:级DisplayObjectContainer =小孩为的DisplayObjectContainer;
如果(childContainer)
{
findControlsRecursive(childContainer,控制);
}
}
}
公共职能findControls()的ArrayCollection
{
VAR控制:ArrayCollection的=新ArrayCollection的();
findControlsRecursive(Application.application为的DisplayObjectContainer,控制);
返回控制;
}
I have various custom component instances in my flex app. I want to loop through them recursively and get their instance Ids. The recursive part is very important to me. Can someone tell me what's the best way to do it? I have tried doing this, but it didn't do recursive:
for each (var myItem:* in this.MasterContainer.childDescriptors)
{
trace(myItem.id);
}
解决方案
This will do it:
private function findControlsRecursive(current:DisplayObjectContainer, controls:ArrayCollection):void
{
for(var idx:int = 0; idx < current.numChildren; idx++)
{
var child:DisplayObject = current.getChildAt(idx);
controls.addItem(child.name);
var childContainer:DisplayObjectContainer = child as DisplayObjectContainer;
if(childContainer)
{
findControlsRecursive(childContainer, controls);
}
}
}
public function findControls():ArrayCollection
{
var controls:ArrayCollection = new ArrayCollection();
findControlsRecursive(Application.application as DisplayObjectContainer, controls);
return controls;
}
这篇关于通过每一个组件实例递归迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文