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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Drag and drop in AIR<br />

Once a drag gesture has started, the Clipboard object can only be accessed from within an ev<strong>en</strong>t handler for the<br />

nativeDragEnter, nativeDragOver, and nativeDragDrop ev<strong>en</strong>ts. After the drag gesture has <strong>en</strong>ded, the Clipboard<br />

object cannot be read or reused.<br />

An application object can be transferred as a refer<strong>en</strong>ce and as a serialized object. Refer<strong>en</strong>ces are only valid within the<br />

originating application. Serialized object transfers are valid betwe<strong>en</strong> AIR applications, but can only be used with<br />

objects that remain valid wh<strong>en</strong> serialized and deserialized. Objects that are serialized are converted into the Action<br />

Message Format for ActionScript 3 (AMF3), a string-based data-transfer format.<br />

Working with the Flex framework<br />

In most cases, it is better to use the Adobe® Flex drag-and-drop API wh<strong>en</strong> building Flex applications. The Flex<br />

framework provides an equival<strong>en</strong>t feature set wh<strong>en</strong> a Flex application is run in AIR (it uses the AIR<br />

NativeDragManager internally). Flex also maintains a more limited feature set wh<strong>en</strong> an application or compon<strong>en</strong>t is<br />

running within the more restrictive browser <strong>en</strong>vironm<strong>en</strong>t. AIR classes cannot be used in compon<strong>en</strong>ts or applications<br />

that run outside the AIR run-time <strong>en</strong>vironm<strong>en</strong>t.<br />

Supporting the drag-out gesture<br />

Adobe AIR 1.0 and later<br />

To support the drag-out gesture, you must create a Clipboard object in response to a mouseDown ev<strong>en</strong>t and s<strong>en</strong>d it to<br />

the NativeDragManager.doDrag() method. Your application can th<strong>en</strong> list<strong>en</strong> for the nativeDragComplete ev<strong>en</strong>t on<br />

the initiating object to determine what action to take wh<strong>en</strong> the user completes or abandons the gesture.<br />

Preparing data for transfer<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

To prepare data or an object for dragging, create a Clipboard object and add the information to be transferred in one<br />

or more formats. You can use the standard data formats to pass data that can be translated automatically to native<br />

clipboard formats, and application-defined formats to pass objects.<br />

If it is computationally exp<strong>en</strong>sive to convert the information to be transferred into a particular format, you can supply<br />

the name of a handler function to perform the conversion. The function is called if and only if the receiving compon<strong>en</strong>t<br />

or application reads the associated format.<br />

For more information on clipboard formats, see “Clipboard data formats” on page 598.<br />

The following example illustrates how to create a Clipboard object containing a bitmap in several formats: a Bitmap<br />

object, a native bitmap format, and a file list format containing the file from which the bitmap was originally loaded:<br />

import flash.desktop.Clipboard;<br />

import flash.display.Bitmap;<br />

import flash.filesystem.File;<br />

public function createClipboard(image:Bitmap, sourceFile:File):Clipboard{<br />

var transfer:Clipboard = new Clipboard();<br />

transfer.setData("CUSTOM_BITMAP", image, true); //Flash object by value and by refer<strong>en</strong>ce<br />

transfer.setData(ClipboardFormats.BITMAP_FORMAT, image.bitmapData, false);<br />

transfer.setData(ClipboardFormats.FILE_LIST_FORMAT, new Array(sourceFile), false);<br />

return transfer;<br />

}<br />

Last updated 6/6/2012<br />

609

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

Saved successfully!

Ooh no, something went wrong!