1 Reply Latest reply on Jan 29, 2011 8:26 AM by saisri2k2

    How to I target an embedded component

    SiHoop Level 1

      I have a component (textContainer) that contains 10 children. I'm trying to find the number of children in each component. I'd like to be able to write:

       

      for(var i:int=0;i<10;i++){

           trace("Number kids="+this.textContainer.getChildAt(i).numChildren)

      }

      but that gives me an error. I have to write

      trace("Number kids="+this.textContainer.getChildAt(i)["numChildren"]

       

      this works and I get the correct value: 1

       

      However, I get an error if I write

      trace("Number kids="+this.textContainer.getChildAt(i)["getChildAt(0)"]

      What am I doing wrong and what is the correct way to access the child?

      Thank you!

        • 1. Re: How to I target an embedded component
          saisri2k2 Level 4

          SiHoop wrote:

           

          I have a component (textContainer) that contains 10 children. I'm trying to find the number of children in each component. I'd like to be able to write:

           

          for(var i:int=0;i<10;i++){

               trace("Number kids="+this.textContainer.getChildAt(i).numChildren)

          }

          but that gives me an error. I have to write

          trace("Number kids="+this.textContainer.getChildAt(i)["numChildren"]

           

          this works and I get the correct value: 1

           

          However, I get an error if I write

          trace("Number kids="+this.textContainer.getChildAt(i)["getChildAt(0)"]

          What am I doing wrong and what is the correct way to access the child?

          Thank you!

          )["getChildAt(0)"]  does not work

           

          you might consider writing

           

          (this.textContainer.getChildAt(i) as DisplayObject).numChildren

           

          & (this.textContainer.getChildAt(i) as DisplayObject).getChildAt(0)

           

          bt you are trying somethiing with string here...

           

          this.textContainer.getChildAt(i)["getChildAt(0)"]