Drag and drop image on Canvas with ghost image : Image Drag Drop « Graphics « Flex






Drag and drop image on Canvas with ghost image

Drag and drop image on Canvas with ghost image
           

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
    
    import mx.managers.DragManager;
    import mx.core.DragSource;
    import mx.events.DragEvent;
    import flash.events.MouseEvent;
    
    [Embed(source='logo.jpg')]
    public var globeImage:Class;
    
    private function mouseOverHandler(event:MouseEvent):void
    {
        var dragInitiator:Image = Image(event.currentTarget);
        var ds:DragSource = new DragSource();
        ds.addData(dragInitiator, "img");
        
        var imageProxy:Image = new Image();
        imageProxy.source = globeImage;
        DragManager.doDrag(dragInitiator, ds, event,imageProxy, -5, -5, 1.00);
    }
    private function dragEnterHandler(event:DragEvent):void {
        if (event.dragSource.hasFormat("img"))
        {
            DragManager.acceptDragDrop(Canvas(event.currentTarget));
        }
    }
    private function dragDropHandler(event:DragEvent):void {
        Image(event.dragInitiator).x =Canvas(event.currentTarget).mouseX;
        Image(event.dragInitiator).y =Canvas(event.currentTarget).mouseY;
    }
  
    </mx:Script>
    <mx:Canvas width="100" height="100" backgroundColor="#FF00FF" 
               dragEnter="dragEnterHandler(event);"
               dragDrop="dragDropHandler(event);">
        <mx:Image id="myimg" source="@Embed(source='logo.jpg')" mouseMove="mouseOverHandler(event);"/>
    </mx:Canvas>
</mx:Application>

   
    
    
    
    
    
    
    
    
    
    
  








Related examples in the same category

1.Creating a custom drag imageCreating a custom drag image
2.Drag and drop image on CanvasDrag and drop image on Canvas
3.Drag to copy image between two Canvas controlsDrag to copy image between two Canvas controls
4.Drag and move an Image from one Canvas to another CanvasDrag and move an Image from one Canvas to another Canvas
5.Use Image control to load a draggable image into a Canvas container.Use Image control to load a draggable image into a Canvas container.
6.Drag and Drop Image, Copy MoveDrag and Drop Image, Copy Move