In a previous tutorial we have seen how to drag and drop images from a native application (Fireworks) to Adobe Air and between two air apps. In this post I will show how to drag and drop text from a document (pdf, html, txt) into a text area of an Adobe Air application.
Our application has to specify two handlers: nativeDragEnter and nativeDragDrop (lines 3-4). In the first we will check whether the content in the clipboard is textual (lines 11-12), in the second we will dump the content in a Text component (line 17).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="vertical" 
    nativeDragEnter="dragEnterHandler(event)" 
    nativeDragDrop="dropHandler(event)">
 
    <mx:Script>
	<![CDATA[
 
	private function dragEnterHandler(e:NativeDragEvent):void {
	    // check whether content is textual
	    if (e.clipboard.hasFormat(ClipboardFormats.TEXT_FORMAT)) {
	 	NativeDragManager.acceptDragDrop(this);
	    }
	}
 
	private function dropHandler(e:NativeDragEvent):void {
	    droppedText.text = e.clipboard.getData(ClipboardFormats.TEXT_FORMAT) as String;
	}
 
	]]>
    </mx:Script>
 
    <mx:Text id="droppedText" width="100%"/>
</mx:WindowedApplication>

Let’s check whether it works!

Happy drag&dropping :)
Source code is available.
In the next tutorial we will see how to drag and drop images from the file system.
Stay tuned.

Similar Posts

Share

One Comment

    Leave a Reply