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

<br />

Uses "-webkit-user-select:none" style.<br />

<br />

<br />

<br />

<br />

Target<br />

Drag items from the source list (or elsewhere).<br />

<br />

Plain textHtml textURLFile listBitmap<br />

Data<br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />

<br />

<br />

<br />

<br />

<br />

Handling file drops in non-application HTML sandboxes<br />

Adobe AIR 1.0 and later<br />

Non-application cont<strong>en</strong>t cannot access the File objects that result wh<strong>en</strong> files are dragged into an AIR application. Nor<br />

is it possible to pass one of these File objects to application cont<strong>en</strong>t through a sandbox bridge. (The object properties<br />

must be accessed during serialization.) However, you can still drop files in your application by list<strong>en</strong>ing for the AIR<br />

nativeDragDrop ev<strong>en</strong>ts on the HTMLLoader object.<br />

Normally, if a user drops a file into a frame that hosts non-application cont<strong>en</strong>t, the drop ev<strong>en</strong>t does not propagate from<br />

the child to the par<strong>en</strong>t. However, since the ev<strong>en</strong>ts dispatched by the HTMLLoader (which is the container for all<br />

HTML cont<strong>en</strong>t in an AIR application) are not part of the HTML ev<strong>en</strong>t flow, you can still receive the drop ev<strong>en</strong>t in<br />

application cont<strong>en</strong>t.<br />

To receive the ev<strong>en</strong>t for a file drop, the par<strong>en</strong>t docum<strong>en</strong>t adds an ev<strong>en</strong>t list<strong>en</strong>er to the HTMLLoader object using the<br />

refer<strong>en</strong>ce provided by window.htmlLoader:<br />

window.htmlLoader.addEv<strong>en</strong>tList<strong>en</strong>er("nativeDragDrop",function(ev<strong>en</strong>t){<br />

var filelist = ev<strong>en</strong>t.clipboard.getData(air.ClipboardFormats.FILE_LIST_FORMAT);<br />

air.trace(filelist[0].url);<br />

});<br />

The following example uses a par<strong>en</strong>t docum<strong>en</strong>t that loads a child page into a remote sandbox (http://localhost/). The<br />

par<strong>en</strong>t list<strong>en</strong>s for the nativeDragDrop ev<strong>en</strong>t on the HTMLLoader object and traces out the file url.<br />

Last updated 6/6/2012<br />

621

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

Saved successfully!

Ooh no, something went wrong!