1 Reply Latest reply on Jul 27, 2006 5:48 AM by a.neko®

    Accessing nested UIComponents

    a.neko® Level 1
      The aim of the script is to be able to access component's chldren, and their children, and their children, etc... by their index.

      I've tried the following:

      // script

      public function deployNesting():void {

      var container:Canvas= new Canvas();
      var chldA:Canvas = new Canvas();
      var chldB:Canvas = new Canvas();
      var chldC:Canvas = new Canvas();


      public function accessNesting():void {
      trace(this.childAt(0).childAt(0)) // error 1119*
      trace(this.childAt(0).numChildren) // error 1119*

      *1119 : Access of possibly undefined property numChildren through a reference with static type flash.display:DisplayObject.

      I'm aware that such nesting is not usually a best practice, but in some cases it is required, and I would appreciate an advice on this issue.

        • 1. Accessing nested UIComponents
          a.neko® Level 1
          Well... It's time to assume the therapeutical values of this forum in my particular case : ) One more time, just after recurring to all posiible ways to solve it, and afterwards posting a topic here, I change my approach and find the solution...

          In this case it is required to cast the return of all the getChildAt() in the nesting structure, except the last one.

          You can access a nested child to add a new child to it's display list as follows:


          Accessing a deeply nested child's name property looks as follows:



          Somewhat complicated, but solves the problem of accessing nested children when, for instance, the variables used to create them are gone, or to freely iterate through nested display lists...

          (Verified with Flex 2.0 Builder mx.* components, but I suppose it works also for flash.display.* objects.)