Function to retrieve all children for an application or a View.

20 views
Skip to first unread message

Vaibhav/Steve

unread,
Jan 7, 2010, 3:02:23 PM1/7/10
to Flex India Community
Hi,

Sometimes, we want to access all/some UIComponents of the application
or a particular view.
I have written a simple function using the recursion concept to get it
done.
Function will push all the UIComponents in arrChilds:Array, which can
be further filtered to get a particular components, like all Buttons /
HBOx / TextInput.. etc.

To invoke the function, you just need to give the object of the view
and its class name as parameter. eg.

getDocumentChildrens(this,this.className); will retrieve all the
components for the current view.


private var arrChilds:Array;
private function getDocumentChildrens
(obj:Object,className:String=""):void
{

if(obj.className == className)
arrChilds = new Array();
else
arrChilds.push(obj);
if(!obj.hasOwnProperty("getChildren"))
return;
var arr:Array = obj.getChildren();
for each(var obj1:Object in arr)
{
getDocumentChildrens(obj1);
}
}

Vaibhav.
Software Engineer.
HCL America Inc.
Quincy, MA, USA.

Reply all
Reply to author
Forward
0 new messages