29.04.2013 Views

ACTIONSCRIPT 3.0

Create successful ePaper yourself

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

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

Copy and paste<br />

Transfer mode Description<br />

ClipboardTransferModes.ORIGINAL_ONLY Only a reference is returned. If no reference is available, a null value is returned.<br />

ClipboardTransferModes.ORIGINAL_PREFFERED A reference is returned, if available. Otherwise a serialized copy is returned.<br />

ClipboardTransferModes.CLONE_ONLY Only a serialized copy is returned. If no serialized copy is available, a null value is<br />

returned.<br />

ClipboardTransferModes.CLONE_PREFFERED A serialized copy is returned, if available. Otherwise a reference is returned.<br />

Reading and writing custom data formats<br />

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

When writing an object to the clipboard, you can use any string that does not begin with the reserved prefixes air: or<br />

flash: for the format parameter. Use the same string as the format to read the object. The following examples<br />

illustrate how to read and write objects to the clipboard:<br />

public function createClipboardObject(object:Object):Clipboard{<br />

var transfer:Clipboard = Clipboard.generalClipboard;<br />

transfer.setData("object", object, true);<br />

}<br />

To extract a serialized object from the clipboard object (after a drop or paste operation), use the same format name<br />

and the CLONE_ONLY or CLONE_PREFFERED transfer modes.<br />

var transfer:Object = clipboard.getData("object", ClipboardTransferMode.CLONE_ONLY);<br />

A reference is always added to the Clipboard object. To extract the reference from the clipboard object (after a drop or<br />

paste operation), instead of the serialized copy, use the ORIGINAL_ONLY or ORIGINAL_PREFFERED transfer modes:<br />

var transferredObject:Object =<br />

clipboard.getData("object", ClipboardTransferMode.ORIGINAL_ONLY);<br />

References are valid only if the Clipboard object originates from the current application. Use the<br />

ORIGINAL_PREFFERED transfer mode to access the reference when it is available, and the serialized clone when the<br />

reference is not available.<br />

Deferred rendering<br />

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

If creating a data format is computationally expensive, you can use deferred rendering by supplying a function that<br />

supplies the data on demand. The function is called only if a receiver of the drop or paste operation requests data in<br />

the deferred format.<br />

The rendering function is added to a Clipboard object using the setDataHandler() method. The function must<br />

return the data in the appropriate format. For example, if you called<br />

setDataHandler(ClipboardFormat.TEXT_FORMAT, writeText), then the writeText() function must return a<br />

string.<br />

If a data format of the same type is added to a Clipboard object with the setData() method, that data takes precedence<br />

over the deferred version (the rendering function is never called). The rendering function may or may not be called<br />

again if the same clipboard data is accessed a second time.<br />

Note: On Mac OS X, deferred rendering works only with custom data formats. With standard data formats, the rendering<br />

function is called immediately.<br />

Last updated 4/22/2013<br />

601

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

Saved successfully!

Ooh no, something went wrong!