13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Drag and drop in AIR<br />

import flash.desktop.NativeDragManager;<br />

import flash.ev<strong>en</strong>ts.NativeDragEv<strong>en</strong>t;<br />

public function onDragIn(ev<strong>en</strong>t:NativeDragEv<strong>en</strong>t):void{<br />

NativeDragManager.dropAction = NativeDragActions.MOVE;<br />

if(ev<strong>en</strong>t.clipboard.hasFormat(ClipboardFormats.TEXT_FORMAT)){<br />

NativeDragManager.acceptDragDrop(this); //'this' is the receiving compon<strong>en</strong>t<br />

}<br />

}<br />

Completing the drop<br />

Adobe AIR 1.0 and later<br />

Wh<strong>en</strong> the user drops a dragged item on an interactive object that has accepted the gesture, the interactive object<br />

dispatches a nativeDragDrop ev<strong>en</strong>t. The handler for this ev<strong>en</strong>t can extract the data from the clipboard property of<br />

the ev<strong>en</strong>t object.<br />

Wh<strong>en</strong> the clipboard contains an application-defined format, the transferMode parameter passed to the getData()<br />

method of the Clipboard object determines whether the drag manager returns a refer<strong>en</strong>ce or a serialized version of the<br />

object.<br />

The following example illustrates an ev<strong>en</strong>t handler for the nativeDragDrop ev<strong>en</strong>t:<br />

import flash.desktop.Clipboard;<br />

import flash.ev<strong>en</strong>ts.NativeDragEv<strong>en</strong>t;<br />

public function onDrop(ev<strong>en</strong>t:NativeDragEv<strong>en</strong>t):void {<br />

if (ev<strong>en</strong>t.clipboard.hasFormat(ClipboardFormats.TEXT_FORMAT)) {<br />

var text:String =<br />

String(ev<strong>en</strong>t.clipboard.getData(ClipboardFormats.TEXT_FORMAT,<br />

ClipboardTransferMode.ORIGINAL_PREFERRED));<br />

}<br />

Once the ev<strong>en</strong>t handler exits, the Clipboard object is no longer valid. Any attempt to access the object or its data<br />

g<strong>en</strong>erates an error.<br />

Updating the visual appearance of a compon<strong>en</strong>t<br />

Adobe AIR 1.0 and later<br />

A compon<strong>en</strong>t can update its visual appearance based on the NativeDragEv<strong>en</strong>t ev<strong>en</strong>ts. The following table describes the<br />

types of changes that a typical compon<strong>en</strong>t would make in response to the differ<strong>en</strong>t ev<strong>en</strong>ts:<br />

Ev<strong>en</strong>t Description<br />

nativeDragStart The initiating interactive object can use the nativeDragStart ev<strong>en</strong>t to provide visual feedback that the<br />

drag gesture originated from that interactive object.<br />

nativeDragUpdate The initiating interactive object can use the nativeDragUpdate ev<strong>en</strong>t to update its state during the gesture.<br />

(This ev<strong>en</strong>t does not exist in AIR for Linux.)<br />

nativeDragEnter A pot<strong>en</strong>tial receiving interactive object can use this ev<strong>en</strong>t to take the focus, or indicate visually that it can or<br />

cannot accept the drop.<br />

Last updated 6/6/2012<br />

613

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!