Simple drag and drop example
This is a straight forward article on coding up a drag and drop application in AIR, along with the actual application that can be downloaded (with source).
This is a beta 1 example that may not work with the beta 2 runtime as it looks like changes have been made to the native drag and drop libaries - i will test and update when I can.
The example is very simple and has commenting in the source code on what is being done.
Overview
The steps required for this drag and drop example are:
- set up the required event handlers so that drag and drop can be detected and acted on - in this example that is dragEnter, dragExit and dragDrop
- In dragEnter check the initiator of the drag action and if ok inform the dragManager which object will accept the dragged item
- dragExit is used to provide visual indication that the object will accept the dragged item (border color change)
- dragDrop is used to gather the details of the object that was dropped and pass the details to the method that displays the image
There is a lot of stuff missing, such as checking filetypes, handling more that one file etc, etc. But the the code here is just an example of getting drag and drop working so it has been kept as simple as possible.
The attached files that can be downloaded are as follows
- dragdrop.zip - zip of the Flex builder project directory with all files
- dragdrop.air - the installable drap and drop example application
To run and install the AIR application you will need the appropriate runtime. see http://labs.adobe.com/downloads/air.html for more details.
| Attachment | Size |
|---|---|
| dragdrop.zip | 1.67 MB |
| dragdrop.air | 722.93 KB |
