0 Replies Latest reply on Aug 22, 2009 11:49 PM by flCoder74

    Pass Object in dragSource

    flCoder74 Level 1

      Is there a way to pass the entire object to the canvas where I drop the panel, instead of specifically setting the height, width, title, etc?

       

      The example below drops the panel to the second canvas as expected, but I'm having to set the height and width, and anything else that I might have in the panel. So I want to pass the whole panel, and fields in the panel and their values, etc. How do I do this????

       

       

       

      <?xml version="1.0"?>

      <mx:Application

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal">

       

       

      <mx:Script>

      <![CDATA[

       

      import mx.managers.DragManager;

       

      import mx.core.DragSource;

       

      import mx.events.DragEvent;

       

      import flash.events.MouseEvent;

       

       

      private function mouseOverHandler(event:MouseEvent):void

      {

       

      var dragInitiator:Panel=Panel(event.currentTarget);

       

      var ds:DragSource = new DragSource();

      ds.addData(dragInitiator,

      "format");

       

      var PanelProxy:Panel = new Panel();

      PanelProxy.height=myPanel.height;

      PanelProxy.width=myPanel.width;

      DragManager.doDrag(dragInitiator, ds, event,

      PanelProxy, 0, 0, 1.00);

      }

       

       

      private function dragEnterHandler(event:DragEvent):void {

       

      if (event.dragSource.hasFormat("format"))

      DragManager.acceptDragDrop(Canvas(event.currentTarget));

      }

       

       

      private function dragOverHandler(event:DragEvent):void

      {

       

      if (event.dragSource.hasFormat("format")) {

       

      if (event.ctrlKey) {

      DragManager.showFeedback(DragManager.COPY);

       

      return;

      }

       

      else {

      DragManager.showFeedback(DragManager.MOVE);

       

      return;

      }

      }

       

      DragManager.showFeedback(DragManager.NONE);

      }

       

       

      private function dragDropHandler(event:DragEvent):void {

       

      if (event.dragSource.hasFormat("format")) {

       

      var draggedPanel:Panel = event.dragSource.dataForFormat('format') as Panel;

       

      var dropCanvas:Canvas = event.currentTarget as Canvas;

       

      var newPanel:Panel = new Panel();

      newPanel.x = dropCanvas.mouseX;

      newPanel.y = dropCanvas.mouseY;

      newPanel.height = draggedPanel.height;

      newPanel.width = draggedPanel.height;

      dropCanvas.addChild(newPanel);

      }

      }

       

       

      private function dragCompleteHandler(event:DragEvent):void {

       

      var draggedPanel:Panel =

      event.dragInitiator

      as Panel;

       

      var dragInitCanvas:Canvas =

      event.dragInitiator.parent

      as Canvas;

       

       

      if (event.action == DragManager.MOVE)

      dragInitCanvas.removeChild(draggedPanel);

      }

      ]]>

       

      </mx:Script>

       

       

      <mx:Canvas

      width="

      250" height="500"

      borderStyle="

      solid"

      backgroundColor="

      #DDDDDD">

       

       

      <mx:Panel id="myPanel" x="10" y="192" width="150" height="150" layout="absolute" title="Test Panel" mouseMove="mouseOverHandler(event);" dragComplete="dragCompleteHandler(event);"/>

       

      </mx:Canvas>

       

       

      <mx:Canvas

      width="

      250" height="500"

      borderStyle="

      solid"

      backgroundColor="

      #DDDDDD"

      dragEnter="dragEnterHandler(event);"

      dragOver="dragOverHandler(event);"

      dragDrop="dragDropHandler(event);"

      >

       

      </mx:Canvas>

      </mx:Application>