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

Working with the file system<br />

Navigating to relative paths<br />

Adobe AIR 1.0 and later<br />

You can use the resolvePath() method to obtain a path relative to another giv<strong>en</strong> path. For example, the following<br />

code sets a File object to point to an "AIR Test" subdirectory of the user's home directory:<br />

var file:File = File.userDirectory;<br />

file = file.resolvePath("AIR Test");<br />

You can also use the url property of a File object to point it to a directory based on a URL string, as in the following:<br />

var urlStr:String = "file:///C:/AIR Test/";<br />

var file:File = new File()<br />

file.url = urlStr;<br />

For more information, see “Modifying File paths” on page 676.<br />

Letting the user browse to select a directory<br />

Adobe AIR 1.0 and later<br />

The File class includes the browseForDirectory() method, which pres<strong>en</strong>ts a system dialog box in which the user can<br />

select a directory to assign to the object. The browseForDirectory() method is asynchronous. The File object<br />

dispatches a select ev<strong>en</strong>t if the user selects a directory and clicks the Op<strong>en</strong> button, or it dispatches a cancel ev<strong>en</strong>t if<br />

the user clicks the Cancel button.<br />

For example, the following code lets the user select a directory and outputs the directory path upon selection:<br />

var file:File = new File();<br />

file.addEv<strong>en</strong>tList<strong>en</strong>er(Ev<strong>en</strong>t.SELECT, dirSelected);<br />

file.browseForDirectory("Select a directory");<br />

function dirSelected(e:Ev<strong>en</strong>t):void {<br />

trace(file.nativePath);<br />

}<br />

Note: On Android, the browseForDirectory() method is not supported. Calling this method has no effect; a cancel<br />

ev<strong>en</strong>t is dispatched immediately. To allow users to select a directory, use a custom, application-defined dialog, instead.<br />

Pointing to the directory from which the application was invoked<br />

Adobe AIR 1.0 and later<br />

You can get the directory location from which an application is invoked, by checking the curr<strong>en</strong>tDirectory property<br />

of the InvokeEv<strong>en</strong>t object dispatched wh<strong>en</strong> the application is invoked. For details, see “Capturing command line<br />

argum<strong>en</strong>ts” on page 878.<br />

Pointing a File object to a file<br />

Adobe AIR 1.0 and later<br />

There are differ<strong>en</strong>t ways to set the file to which a File object points.<br />

Last updated 6/6/2012<br />

674

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

Saved successfully!

Ooh no, something went wrong!