Specify a Drag Proxy : Drag Drop « Development « Flex






Specify a Drag Proxy

Specify a Drag Proxy
          

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal">
    <mx:Script>
        
            import mx.core.BitmapAsset;
            import mx.core.DragSource;
            import mx.events.DragEvent;
            import mx.managers.DragManager;

            private function mouseDownHandler( evt:MouseEvent ):void
            {
                var initiator:Box = evt.currentTarget as Box;
                var proxyBox:BitmapAsset = new BitmapAsset();
                proxyBox.bitmapData = new BitmapData( initiator.width,initiator.height );
                proxyBox.bitmapData.draw( initiator );               
               
                var dragSource:DragSource = new DragSource();
                dragSource.addData( initiator, "box" );

                DragManager.doDrag( initiator, dragSource, evt,proxyBox, 0, 0, 0.5 );
            }
            private function dragEnterHandler( evt:DragEvent ):void {
                if( evt.dragSource.hasFormat("box")){
                    DragManager.acceptDragDrop( Canvas( evt.currentTarget ) );
                }
            }
            private function dropHandler( evt:DragEvent ):void {
                var box:Box = Box( evt.dragInitiator );
                box.x = evt.localX ;
                box.y = evt.localY ;
            }
      
    </mx:Script>
    <mx:Canvas id="canvas" width="300" height="300" dragEnter="dragEnterHandler(event);" dragDrop="dropHandler(event);">
        <mx:Box id="dragItem" width="20" height="20" backgroundColor="0x00FFCC" mouseDown="mouseDownHandler(event);"/>
    </mx:Canvas>

</mx:Application>
    

   
    
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Setting the dragMoveEnabled property to move instead of copySetting the dragMoveEnabled property to move instead of copy
2.Dragging and dropping within a component, to allow orderingDragging and dropping within a component, to allow ordering
3.Create DragSource object and add data to itCreate DragSource object and add data to it
4.Performing a two-way drag and dropPerforming a two-way drag and drop
5.Dragging and dropping in the same controlDragging and dropping in the same control
6.The drag initiators, and drop targetThe drag initiators, and drop target
7.Get Drag source data formatGet Drag source data format
8.Press control key as drag and dropPress control key as drag and drop
9.Canvas Drag and DropCanvas Drag and Drop
10.Specifying the drag indicator by using the DragSpecifying the drag indicator by using the Drag
11.Enable and Disable Drag OperationsEnable and Disable Drag Operations
12.Drag Drop To ComponentDrag Drop To Component
13.Set liveDragging to true to dispatch change event continuously as moving the thumbSet liveDragging to true to dispatch change event continuously as moving the thumb
14.Get drag source from DragEventGet drag source from DragEvent
15.Canvas drag enter eventCanvas drag enter event
16.Explpicitly handle the dragOver eventExplpicitly handle the dragOver event