Specifying the drag indicator by using the Drag : Drag Drop « Development « Flex






Specifying the drag indicator by using the Drag

Specifying the drag indicator by using the Drag
          

<!--
Code from Flex 4 Documentation "Using Adobe Flex 4".

This user guide is licensed for use under the terms of the Creative Commons Attribution 
Non-Commercial 3.0 License. 

This License allows users to copy, distribute, and transmit the user guide for noncommercial 
purposes only so long as 
  (1) proper attribution to Adobe is given as the owner of the user guide; and 
  (2) any reuse or distribution of the user guide contains a notice that use of the user guide is governed by these terms. 
The best way to provide notice is to include the following link. 
To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/

-->



    <!-- dragdrop\DandDImageProxy.mxml -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Script> 
         
        //Import classes so you don't have to use full names. 
        import mx.managers.DragManager; 
        import mx.core.DragSource; 
        import mx.events.DragEvent; 
        import flash.events.MouseEvent; 
        // Embed icon image. 
        [Embed(source='a.jpg')] 
        public var globeImage:Class; 
        // The mouseMove event handler for the Image control 
        // initiates the drag-and-drop operation. 
        private function mouseOverHandler(event:MouseEvent):void 
        { 
            var dragInitiator:Image=Image(event.currentTarget); 
            var ds:DragSource = new DragSource(); 
            ds.addData(dragInitiator, "img"); 
            // The drag manager uses the Image control 
            // as the drag indicator and sets the alpha to 1.0 (opaque), 
            // so it appears to be dragged across the Canvas. 
            var imageProxy:Image = new Image(); 
            imageProxy.source = globeImage; 
            imageProxy.height=15; 
            imageProxy.width=15; 
            DragManager.doDrag(dragInitiator, ds, event, 
            imageProxy, -15, -15, 1.00); 
        } 
        // The dragEnter event handler for the Canvas container 
        // enables dropping. 
        private function dragEnterHandler(event:DragEvent):void { 
            if (event.dragSource.hasFormat("img")) 
            { 
                DragManager.acceptDragDrop(Canvas(event.currentTarget)); 
            } 
        } 
        // The dragDrop event handler for the Canvas container 
        // sets the Image control's position by 
        // "dropping" it in its new location. 
        private function dragDropHandler(event:DragEvent):void { 
            Image(event.dragInitiator).x = Canvas(event.currentTarget).mouseX; 
            Image(event.dragInitiator).y = Canvas(event.currentTarget).mouseY; 
        } 
      
    </fx:Script>
    <!-- The Canvas is the drag target -->
    <mx:Canvas id="v1" width="500" height="500" borderStyle="solid"
        backgroundColor="#DDDDDD" dragEnter="dragEnterHandler(event);"
        dragDrop="dragDropHandler(event);">
        <!-- The image is the drag initiator. -->
        <mx:Image id="myimg" source="@Embed(source='a.jpg')"
            mouseMove="mouseOverHandler(event);" />
    </mx:Canvas>
</s: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.Specify a Drag ProxySpecify a Drag Proxy
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