Explpicitly handle the dragOver event : Drag Drop « Development « Flex






Explpicitly handle the dragOver event

Explpicitly handle the dragOver event
           

<!--
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\DandDListToListShowFeedbackSpark.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"
    creationComplete="initApp();">
    <s:layout>
        <s:VerticalLayout />
    </s:layout>
    <fx:Script> 
         
        import mx.collections.ArrayCollection; 
        import mx.events.DragEvent; 
        import mx.managers.DragManager; 
        import spark.layouts.supportClasses.DropLocation; 
        private function initApp():void { 
            firstList.dataProvider = new ArrayCollection([ 
            {label:"First", data:"1"}, 
            {label:"Second", data:"2"}, 
            {label:"Third", data:"3"}, 
            {label:"Fourth", data:"4"} 
            ]); 
            secondList.dataProvider = new ArrayCollection([]); 
        } 
        // Variable to store original border color. 
        private var tempBorderColor:uint; 
        // Flag to indicate that tempBorderColor has been set. 
        private var borderColorSet:Boolean = false; 
        private function dragOverHandler(event:DragEvent):void { 
            // Explpicitly handle the dragOver event. 
            event.preventDefault(); 
            // Since you are explicitly handling the dragOver event, 
            // call showDropIndicator() to have the drop target 
            // display the drop indicator. 
            // The drop indicator is removed 
            // automatically for the list controls by the built-in 
            // event handler for the dragDrop event. 
            var dropLocal:DropLocation = 
            event.currentTarget.layout.calculateDropLocation(event); 
            event.currentTarget.layout.showDropIndicator(dropLocal); 
            if (event.dragSource.hasFormat("itemsByIndex")) 
            { 
                // Set the border to green to indicate that 
                // this is a drop target. 
                // Since the dragOver event is dispatched continuosly 
                // as you move over the drop target, only set it once. 
                if (borderColorSet == false) { 
                    tempBorderColor = event.currentTarget.getStyle('borderColor'); 
                    borderColorSet = true; 
                } 
                // Set the drag-feedback indicator based on the 
                // type of drag-and-drop operation. 
                event.currentTarget.setStyle('borderColor', 'green'); 
                if (event.ctrlKey) { 
                    DragManager.showFeedback(DragManager.COPY); 
                    return; 
                }else if (event.shiftKey) { 
                    DragManager.showFeedback(DragManager.LINK); 
                    return; 
                }else { 
                    DragManager.showFeedback(DragManager.MOVE); 
                    return; 
                } 
            } 
            // Drag not allowed. 
            DragManager.showFeedback(DragManager.NONE); 
        } 
        private function dragDropHandler(event:DragEvent):void { 
            dragExitHandler(event); 
        } 
        // Restore the border color. 
        private function dragExitHandler(event:DragEvent):void { 
            event.currentTarget.setStyle('borderColor', tempBorderColor); 
            borderColorSet = true; 
        } 
      
    </fx:Script>
    <s:HGroup id="myHG">
        <s:List id="firstList" dragEnabled="true" dragMoveEnabled="true" />
        <s:List id="secondList" dropEnabled="true" dragOver="dragOverHandler(event);"
            dragDrop="dragExitHandler(event);" dragExit="dragExitHandler(event);" />
    </s:HGroup>
    <s:Button id="b1" label="Reset" click="initApp();" />
</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.Specifying the drag indicator by using the DragSpecifying the drag indicator by using the Drag
11.Specify a Drag ProxySpecify a Drag Proxy
12.Enable and Disable Drag OperationsEnable and Disable Drag Operations
13.Drag Drop To ComponentDrag Drop To Component
14.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
15.Get drag source from DragEventGet drag source from DragEvent
16.Canvas drag enter eventCanvas drag enter event