Adobe Flex 3 Help

Using drag and drop with Flex applications running in AIR

When a Flex application runs in Adobe® AIR™, you can control whether the application uses the Flex drag manager or the AIR drag manager. These drag managers are implemented by the classes mx.managers.DragManager (Flex drag manager) and flash.desktop.NativeDragManager (AIR drag manager).

Internally, the Flex mx.managers.DragManager class uses an implementation class to determine which drag manager to use. It uses either the Flex mx.managers.DragManagerImpl class, or the AIR mx.managers.NativeDragManagerImpl class.

By default, a Flex application defined by the <mx:Application> tag uses the Flex drag-and-drop manager, even when the Flex application runs in AIR. If you run your Flex application in AIR, and you want to take advantage of the AIR drag-and-drop manager to drag and drop items from outside of AIR, then you must configure the Flex mx.managers.DragManager class to use the AIR drag-and-drop manager.

There are three scenarios that determine which drag-and-drop manager your Flex application uses when running in AIR:

  1. Your main application file uses the <mx:Application> tag. In this scenario, you use the Flex drag-and-drop manager, and cannot drag and drop items from outside of AIR.
  2. Your main application file uses the <mx:WindowedApplication> tag. In this scenario, you use the AIR drag-and-drop manager, and can drag and drop items from outside of AIR.
  3. Your main application file uses the <mx:Application> tag, but loads the AIR drag-and-drop manager as represented by the mx.managers.NativeDragManagerImpl class. In this scenario, you use the AIR drag-and-drop manager, and can drag and drop items from outside of AIR.

For the third scenario, to use the AIR drag-and-drop manager in your Flex application, you must write your application to link to mx.managers.NativeDragManagerImpl class, and to load it at runtime, as the following example shows:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    initialize="initDandD();"> 

    <mx:Script>
        <![CDATA[        
            // Ensure that the NativeDragManagerImpl class is linked in to your application.
            import mx.managers.NativeDragManagerImpl;
            var placeholder:NativeDragManagerImpl;

            // Handle the initialize event to load the DragManager.
            public function initDandD():void
            {
                // Ensure the DragManager is loaded, so that dragging in an AIR works.
                DragManager.isDragging;
            }
        ]]>
    </mx:Script>

    ...
</mx:Application>

Two drag-and-drop events work differently depending on whether your application runs in Adobe® Flash® Player or AIR, as the following table shows:

Event

Flash Player

AIR

dragEnter

Triggers many times when you move the mouse pointer over any component during a drag and drop operation.

The default value of the DragEvent.action property is DragEvent.MOVE.

Triggers once when you move the mouse pointer over any component during a drag and drop operation.

The default value of the DragEvent.action property is DragEvent.COPY.

dragOver

Triggers many times when you drag an item over a valid drop target.

Triggers many times when you drag an item over any component, even if the component is not a valid drop target.

There are several other differences between the Flex and AIR drag managers, as described below:

Characteristic

Flash player

AIR

Cursors

Flex draws the drag-and-drop cursors.

The operating system draws the cursors.

Styles

Cursor styles and the mx.managers.DragManager.defaultDragImageSkin property are supported.

Cursor styles and the mx.managers.DragManager.defaultDragImageSkin property are ignored.

Drag proxy

You can control the drag proxy.

The operating system controls the drag proxy, but you can still specify a drag image.

Drag image

The drag image of the drag proxy can be an instance of the DisplayObject class, including an animated SWF file, an image, or a Flex component.

 

By default, the drag image is a bitmap created from the object being dragged. It does not change dynamically as the user drags it.

If you pass a drag image to the doDrag() method, it must already be loaded by your application when you call doDrag(), otherwise it will be blank. For more information on the doDrag() method, see Example: Specifying the drag proxy.

Drop animation

The DragProxy class animaties the drag image based on the results of the drop, such as accepted or rejected.

No custom animations can be used. The operating system handles the behavior of the cursor and the drag image.