DragManager.acceptDragDrop : DragManager « Development « Flex






DragManager.acceptDragDrop

DragManager.acceptDragDrop
        
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Script>
    
      import mx.core.DragSource;
      import mx.containers.Canvas;
      import mx.events.DragEvent;
      import mx.managers.DragManager;

      private function beginDragAndDrop(event:MouseEvent):void {
        var canvas:Canvas = Canvas(event.currentTarget);
        var dragSource:DragSource = new DragSource(  );
        var color:uint = canvas.getStyle("backgroundColor");
        dragSource.addData(color, "backgroundColor");
        var proxy:Canvas = new Canvas(  );
        proxy.width = 50;
        proxy.height = 50;
        proxy.setStyle("backgroundColor", color);
        DragManager.doDrag(canvas, dragSource, event, proxy);
      }

      private function dragEnterHandler(event:DragEvent):void {
        var target:Canvas = Canvas(event.currentTarget);
        var initiator:Canvas = Canvas(event.dragInitiator);
        if(target.getStyle("backgroundColor") ==  initiator.getStyle("backgroundColor")) {
          DragManager.acceptDragDrop(target);
        }
      }

      private function dragDropHandler(event:DragEvent):void {
        var target:Canvas = Canvas(event.currentTarget);
        var initiator:Canvas = Canvas(event.dragInitiator);
        if(target.getStyle("backgroundColor") ==  initiator.getStyle("backgroundColor")) {
          vbox.removeChild(initiator);
        }
      }
  
  </mx:Script>
  <mx:HBox width="100%">
    <mx:VBox id="vbox" height="100%">
      <mx:Canvas width="50" height="50" backgroundColor="#00ff80" mouseDown="beginDragAndDrop(event)" />
    </mx:VBox>
    <mx:VRule height="213"/>
    <mx:HBox id="hbox" height="100%">
       <mx:Canvas width="50" height="50" backgroundColor="#00ff80" dragEnter="dragEnterHandler(event)" dragDrop="dragDropHandler(event)" />
       <mx:Canvas width="50" height="50" backgroundColor="#ff8040" dragEnter="dragEnterHandler(event)" dragDrop="dragDropHandler(event)" />
    </mx:HBox>
  </mx:HBox>


</mx:Application>

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.Use DragManager.acceptDragDrop to accept drop targetUse DragManager.acceptDragDrop to accept drop target
2.Use DragManager.showFeedback to show user feed back when drag and drop
3.DragManager.showFeedback(DragManager.LINK);DragManager.showFeedback(DragManager.LINK);
4.DragManager.showFeedback(DragManager.COPY);DragManager.showFeedback(DragManager.COPY);
5.DragManager.showFeedback(DragManager.MOVE);DragManager.showFeedback(DragManager.MOVE);
6.Do the drag with DragManagerDo the drag with DragManager
7.Use DragManager Class and define your own formatUse DragManager Class and define your own format
8.Canvas drag and drop by using DragManager
9.Style for DragManagerStyle for DragManager