12.1. Drag-and-Drop Support
Those of you who have come to AIR from a Flex background understand how to drag objects between native Flex components. The ease of doing this was always one of the killer features of Flex applications. However, owing to Flash player sandbox restrictions, it was never possible to drag a file from the user's file system into a Flash application. This is now possible with AIR. The quick overview of this is that you will have the ability to drag any file type into the AIR application, and it is then up to the application to determine whether or not to accept the file and how to handle that file.
12.1.1. DragIn
Let's start off by creating an application that allows for a file to be dragged in from the file system to the AIR application. Create a new AIR project named Chapter12_DragIn. You should now have a new file named Chapter12_DragIn.mxml. The completed code from this sample will be seen in Listing 12-5.
The first thing we'll need to add to this file is some import statements for the necessary classes to handle drag and drop. The mx.controls.Image class is needed to show the image within the AIR application, and the mx.controls.Alert class will show when an unmapped extension appears. Although the flash.filesystem.File class is not needed when working from the root window of an AIR project, it is best practice to import it. Copy the script block from Listing 12-1 into the Chapter12_DragIn.mxml file.
Example 12-1. The necessary import statements
<mx:Script> ... |
Get Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime 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.