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 />

if( Clipboard.supportsFilePromise )<br />

{ //Create the promise objects<br />

var filePromise:URLFilePromise = new URLFilePromise();<br />

filePromise.request = new URLRequest("http://example.com/article.html");<br />

filePromise.relativePath = "article.html";<br />

}<br />

var image1Promise:URLFilePromise = new URLFilePromise();<br />

image1Promise.request = new URLRequest("http://example.com/images/img_1.jpg");<br />

image1Promise.relativePath = "images/img_1.html";<br />

var image2Promise:URLFilePromise = new URLFilePromise();<br />

image2Promise.request = new URLRequest("http://example.com/images/img_2.jpg");<br />

image2Promise.relativePath = "images/img_2.jpg";<br />

//Put the promise objects onto the clipboard inside an array<br />

var fileList:Array = new Array( filePromise, image1Promise, image2Promise );<br />

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

clipboard.setData( ClipboardFormats.FILE_PROMISE_LIST_FORMAT, fileList );<br />

//Start the drag operation<br />

NativeDragManager.doDrag( dragSource, clipboard );<br />

Implem<strong>en</strong>ting the IFilePromise interface<br />

Adobe AIR 2 and later<br />

To provide file promises for resources that cannot be accessed using a URLFilePromise object, you can implem<strong>en</strong>t the<br />

IFilePromise interface in a custom class. The IFilePromise interface defines the methods and properties used by the<br />

AIR runtime to access the data to be writt<strong>en</strong> to a file once the file promise is dropped.<br />

An IFilePromise implem<strong>en</strong>tation passes another object to the AIR runtime that provides the data for the file promise.<br />

This object must implem<strong>en</strong>t the IDataInput interface, which the AIR runtime uses to read the data. For example, the<br />

URLFilePromise class, which implem<strong>en</strong>ts IFilePromise, uses a URLStream object as the data provider.<br />

AIR can read the data synchronously or asynchronously. The IFilePromise implem<strong>en</strong>tation reports which mode of<br />

access is supported by returning the appropriate value in the isAsync property. If asynchronous data access is<br />

provided, the data provider object must implem<strong>en</strong>t the IEv<strong>en</strong>tDispatcher interface and dispatch the necessary ev<strong>en</strong>ts,<br />

such as op<strong>en</strong>, progress and complete.<br />

You can use a custom class, or one of the following built-in classes, as a data provider for a file promise:<br />

ByteArray (synchronous)<br />

FileStream (synchronous or asynchronous)<br />

Socket (asynchronous)<br />

URLStream (asynchronous)<br />

To implem<strong>en</strong>t the IFilePromise interface, you must provide code for the following functions and properties:<br />

op<strong>en</strong>():IDataInput — Returns the data provider object from which the data for the promised file is read. The<br />

object must implem<strong>en</strong>t the IDataInput interface. If the data is provided asynchronously, the object must also<br />

implem<strong>en</strong>t the IEv<strong>en</strong>tDispatcher interface and dispatch the necessary ev<strong>en</strong>ts (see “Using an asynchronous data<br />

provider in a file promise” on page 626).<br />

Last updated 6/6/2012<br />

624

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

Saved successfully!

Ooh no, something went wrong!