0 Replies Latest reply on Sep 6, 2007 8:35 AM by

    Problem using Panel.swapChildren()

      Hello,
      I had some fun reorganizing Components in a mx:Panel.
      The execution of this example:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
      <![CDATA[
      public function swapIt() : void {
      trace("Child A:", aPanel.getChildIndex(lbl_A));
      trace("Child B:", aPanel.getChildIndex(lbl_B));
      aPanel.swapChildren(lbl_A, lbl_B);
      }
      ]]>
      </mx:Script>
      <mx:Panel x="10" y="10" width="250" height="200" layout="absolute" title="Bug?" id="aPanel">
      <mx:Label x="10" y="10" text="AAAAA" id="lbl_A"/>
      <mx:Label x="26" y="10" text="BBBBB" color="#ff0000" id="lbl_B"/>
      <mx:Button x="155" y="8" label="Swap!" click="swapIt()"/>
      </mx:Panel>
      </mx:Application>

      ends with an error message:

      ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
      at flash.display::DisplayObjectContainer/swapChildren()
      at SwapChildrenBug/swapIt()
      at SwapChildrenBug/___Button1_click()

      But as you can see in the trace-output: lbl_A and lbl_B are of course children of aPanel. Do I use the function swapChildren() the wrong way? Or is this a bug?
      In my application I use aPanel.setChildIndex(lbl_A, 0) as a workaround, but I'm not sure if this will always work.

      Uwe