0 Replies Latest reply on Oct 2, 2007 7:36 AM by aceflex

    Get all (deep) children in Application

    aceflex
      Hi there,

      is there a way to get all children in application? in the following code, I can get the button_1, panel_1 only. However, can't get the button_2 inside the panel.

      can I get all children in whole application without knowing the container structure? I am new to Flex and appreciate someone can write sample code to me!

      THANKS

      ===========================================================
      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="init();">

      <mx:Script>
      <![CDATA[

      import mx.core.UIComponent;

      private var childrenLength:Number;
      private var targetObj:Object;
      private var targetType:String;

      private function init():void {
      addEventListener(MouseEvent.MOUSE_OVER, getNum);
      }

      private function getNum(event:MouseEvent):void{
      event.preventDefault();

      checkContainer(event);
      }


      private function checkContainer(event:MouseEvent):void{
      childrenLength = UIComponent(event.currentTarget).numChildren;

      for (var i:uint=0; i < childrenLength; i++) {
      targetObj = UIComponent(event.currentTarget).getChildAt(i);
      targetType = getQualifiedClassName(targetObj);
      trace(targetObj);
      }
      }

      ]]>
      </mx:Script>


      <mx:Button id="Button_1" label="Button1"/>

      <mx:Panel id="Panel_1" width="250" height="200" layout="absolute">
      <mx:Button id="Button_2" x="79" y="35" label="Button2"/>
      </mx:Panel>

      </mx:Application>
      ===========================================================