Chapter 8. Drag and Drop Support

Because almost every graphical operating system environment supports some level of drag and drop functionality, AIR provides an easy way to work with drag and drop gestures across multiple platforms. AIR supports both the dragging out and the dropping in of the standard data types; however, ActionScript and JavaScript deal with these gestures in very different ways.

Dragging Data Out of an Application in ActionScript

Problem

You need to drag a file reference from your application to the desktop.

Solution

Use the NativeDragManager class to control the drag-in gesture in your AIR application.

Discussion

In ActionScript, you manage drag and drop gestures with the NativeDragManager class. To support a drag-out gesture specifically, you use the doDrag static method of the NativeDragManager class. You can pass in five parameters; the first two are required: dragInitiator and clipboard.

The first required parameter, dragInitiator, is the object that initiated the drag action. It is required to be an InteractiveObject or a class that inherits from it. The second parameter, clipboard, is an instance of the Clipboard class or a class inheriting from the Clipboard class. In this case, you actually need to instantiate an instance of the Clipboard class and add the data that needs to be passed with the drag-out gesture.

In this example, the user interface consists of a label, a button, and a list:

<mx:Label id="directoryName" fontSize="20" fontWeight="bold" /> <mx:Button ...

Get Adobe AIR 1.5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.