1 Reply Latest reply on May 6, 2009 3:51 PM by ntsiii

    swapChildren() error: supplied DisplayObject must be a child of the caller

    JcFx.Eu

      I've got the following code:

       

      protected function checkDepths($e:Event = null):void
              {
                  try
                  {
                      if ((MyTarget != null)&&(MyTarget.parent != null)&&(MyButton != null)&&(MyButton.parent != null))
                      {
                          if (MyTarget.parent == MyButton.parent)
                          {
                              var targetIndex:int = MyTarget.parent.getChildIndex(MyTarget);
                              var buttonIndex:int = MyButton.parent.getChildIndex(MyButton);
                              if (targetIndex > buttonIndex)
                              {
                                  MyTarget.parent.swapChildren(MyTarget, MyButton);
                              }
                          }
                      }
                  }
                  catch (e:Error)
                  {
                      Console.Debug("TextObject checkDepths");
                      Console.Debug("MyTarget: " + MyTarget);
                      Console.Debug("MyTarget Parent: " + MyTarget.parent);
                      Console.Debug("MyButton: " + MyButton);
                      Console.Debug("MyButton Parent: " + MyButton.parent);
                      Console.Debug("Comparison: " + (MyTarget.parent == MyButton.parent).toString());
                      Console.Debug("Error: " + e);
                  }
              }

       

      MyButton is a UIComponent, MyTarget is a custom class which inherits from UIComponent.

       

      When an error occurs, I'm getting the following output:

       

      DEBUG: TextObject checkDepths

      DEBUG: MyTarget : EditorApp0.Canvas9.Canvas10.DesignArea18.design.Canvas151.Page 3.Layer 1.TemplateTextField340

      DEBUG: MyTarget Parent: EditorApp0.Canvas9.Canvas10.DesignArea18.design.Canvas151.Page 3.Layer 1

      DEBUG: MyButton : EditorApp0.Canvas9.Canvas10.DesignArea18.design.Canvas151.Page 3.Layer 1.UIComponent341

      DEBUG: MyButton Parent: EditorApp0.Canvas9.Canvas10.DesignArea18.design.Canvas151.Page 3.Layer 1

      DEBUG: Comparison: true

      DEBUG: Error: ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

       

      What I don't understand is this: if MyTarget.parent == MyButton.parent, then how can MyTarget.parent.swapChildren(MyTarget, MyButton); throw the following error:  The supplied DisplayObject must be a child of the caller. ?

       

      I'm working with in AS3 with FlashDevelop, targeting FP10, building against flex_sdk_3.2.0.3958.

       

      Many thanks in advance for any assistance.

       

      Jude Fisher

      http://www.jcfx.eu