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

get relativePath():String — Provides the path, including file name, for the created file. The path is resolved<br />

relative to the drop location chos<strong>en</strong> by the user in the drag-and-drop operation. To make sure that the path uses<br />

the proper separator character for the host operating system, use the File.separator constant wh<strong>en</strong> specifying<br />

paths containing directories. You can add a setter function or use a constructor parameter to allow the path to be<br />

set at runtime.<br />

get isAsync():Boolean — Informs the AIR runtime whether the data provider object provides it’s data<br />

asynchronously or synchronously.<br />

close():void — Called by the runtime wh<strong>en</strong> the data is fully read (or an error prev<strong>en</strong>ts further reading). You can<br />

use this function to cleanup resources.<br />

reportError( e:ErrorEv<strong>en</strong>t ):void — Called by the runtime wh<strong>en</strong> an error reading the data occurs.<br />

All of the IFilePromise methods are called by the runtime during a drag-and-drop operation involving the file promise.<br />

Typically, your application logic should not call any of these methods directly.<br />

Using a synchronous data provider in a file promise<br />

Adobe AIR 2 and later<br />

The simplest way to implem<strong>en</strong>t the IFilePromise interface is to use a synchronous data provider object, such as a<br />

ByteArray or a synchronous FileStream. In the following example, a ByteArray object is created, filled with data, and<br />

returned wh<strong>en</strong> the op<strong>en</strong>() method is called.<br />

package<br />

{<br />

import flash.desktop.IFilePromise;<br />

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

import flash.utils.ByteArray;<br />

import flash.utils.IDataInput;<br />

public class SynchronousFilePromise implem<strong>en</strong>ts IFilePromise<br />

{<br />

private const fileSize:int = 5000; //size of file data<br />

private var filePath:String = "SynchronousFile.txt";<br />

public function get relativePath():String<br />

{<br />

return filePath;<br />

}<br />

public function get isAsync():Boolean<br />

{<br />

return false;<br />

}<br />

public function op<strong>en</strong>():IDataInput<br />

{<br />

var fileCont<strong>en</strong>ts:ByteArray = new ByteArray();<br />

//Create some arbitrary data for the file<br />

for( var i:int = 0; i < fileSize; i++ )<br />

Last updated 6/6/2012<br />

625

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

Saved successfully!

Ooh no, something went wrong!