3 Replies Latest reply on Feb 15, 2007 9:47 AM by Xyan_Wert

    Swap Depth

    eddymilner Level 1
      Hey to every one !

      I have a problem with SwapDepth , in ths code i have tow panels , pan1 and pan2 .. on ich panel on mouse down i have a function drag(event) but when i press on panel ,
      i get this error : TypeError: Error #1034: Type Coercion failed: cannot convert "pan2" to flash.display.DisplayObject.

      <mx:Script>

      public function drag(event:Event){
      event.currentTarget.startDrag(false)
      this.swapChildren(event.currentTarget.id, pan2);
      }
      public function dragOff(event:Event){
      event.currentTarget.stopDrag()
      }
      </mx:Script>

      <mx:Panel width="100" height="100" id='pan1' title='pane1' mouseDown="drag(event)" mouseUp="dragOff(event)" >

      </mx:Panel>

      <mx:Panel width="100" height="100" id="pan2" title="pan2" mouseDown="drag(event)" mouseUp="dragOff(event)">

      </mx:Panel>
        • 1. Re: Swap Depth
          leotemp Level 1
          I dunno, try traging canvases instead and arent there drag events already defined in flex?
          • 2. Re: Swap Depth
            eddymilner Level 1
            i dont know how to use another dragging .. anyway canvas or panel or any another component gives me same error !
            • 3. Re: Swap Depth
              Xyan_Wert
              Hi there,
              the problem is that u need to pass a DisplayObject Object to the swapChildren function , event.currentTarget.id makes reference to a property not an object, try this this.swapChildren( DisplayObject(event.currentTarget), pan2);

              your code should now looks like this:

              <mx:Script>

              public function drag(event:Event):void{
              event.currentTarget.startDrag(false)
              this.swapChildren( DisplayObject(event.currentTarget), pan2);
              }
              public function dragOff(event:Event):void{
              event.currentTarget.stopDrag()
              }
              </mx:Script>

              <mx:Panel width="100" height="100" id='pan1' title='pane1' mouseDown="drag(event)" mouseUp="dragOff(event)" >

              </mx:Panel>

              <mx:Panel width="100" height="100" id="pan2" title="pan2" mouseDown="drag(event)" mouseUp="dragOff(event)">

              </mx:Panel>


              i hope this can be useful :)