1 Reply Latest reply on Nov 20, 2007 10:18 AM by JKohn99

    Looping Through Children

    AwesomeDigital3 Level 1
      I have a container (an accordion) that

      Depending upon what my user selects, I may add components as children (That's easy)

      But if they change their initial selection, I may need to remove components

      Is there an easy way to:
      1. Loop through all of the children of a container looking at the name of each
      or
      2. Check if a child exists by name before I try to delete it

      The problem is sometimes I am using removeChild, and the child is not there.

      #1 is prefered then I think I will need to do less hard coding of names.

      Thanks
      Mathias



        • 1. Re: Looping Through Children
          JKohn99 Level 1
          Not sure what you mean by exists by name. Use the contains method
          of the container, before removing it. Below is an override of the removeChild method for a Canvas:

          In this case if the child is a particular type I clean up some of it's references
          then remove it.

          override public function removeChild(child:DisplayObject):DisplayObject
          {


          var o:Object = child;
          if(o is GObject)
          {
          GObject(o).removeAllReferences();
          }
          if(this.contains(child))
          return super.removeChild(child);
          return child;
          }