0 Replies Latest reply on Nov 7, 2006 1:13 AM by parallaxed

    Container references to child DisplayObjects

    parallaxed
      Hi All,

      I'm slightly puzzled over how flex is supposed to behave when addChild() is called on two different containers with a reference to the same component. In the docs here

      http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=L iveDocs_Parts&file=00001853.html

      "If you add a display object that is contained in one display object container to another display object container, it is removed from the first display object container's child list."

      Which implies to me that this code should not throw a runtime exception:

      package testspace
      {
      import mx.controls.*;
      import mx.containers.*;

      public class TestImage extends VBox
      {
      private var mainImage:Image = new Image();
      public function TestImage()
      {
      mainImage.load("someRandom.jpg");
      }

      override protected function createChildren():void
      {
      super.createChildren();
      var tileDisplay:Tile = new Tile();
      tileDisplay.addChild(mainImage);
      addChild(mainImage);
      addChild(tileDisplay);
      }
      }
      }

      For me it throws a "RangeError: Error #2006: The supplied index is out of bounds" - but given what the docs imply, this shouldn't happen, because the tileDisplay container should have the reference to mainImage removed on the second call to addChild().

      Can anyone confirm what's supposed to happen here?