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

Supported AIR URL schemes<br />

Adobe AIR 1.0 and later<br />

In AIR, you can use any of the following URL schemes in defining the url property of a File object:<br />

URL scheme Description<br />

file Use to specify a path relative to the root of the file system. For example:<br />

file:///c:/AIR Test/test.txt<br />

The URL standard specifies that a file URL takes the form file:///. As a special<br />

case, can be the empty string, which is interpreted as "the machine from which the URL is being<br />

interpreted." For this reason, file URLs oft<strong>en</strong> have three slashes (///).<br />

app Use to specify a path relative to the root directory of the installed application (the directory that contains<br />

the application.xml file for the installed application). For example, the following path points to an images<br />

subdirectory of the directory of the installed application:<br />

app:/images<br />

app-storage Use to specify a path relative to the application store directory. For each installed application, AIR defines<br />

a unique application store directory, which is a useful place to store data specific to that application. For<br />

example, the following path points to a prefs.xml file in a settings subdirectory of the application store<br />

directory:<br />

app-storage:/settings/prefs.xml<br />

Finding the relative path betwe<strong>en</strong> two files<br />

Adobe AIR 1.0 and later<br />

You can use the getRelativePath() method to find the relative path betwe<strong>en</strong> two files:<br />

var file1:File = File.docum<strong>en</strong>tsDirectory.resolvePath("AIR Test");<br />

var file2:File = File.docum<strong>en</strong>tsDirectory<br />

file2 = file2.resolvePath("AIR Test/bob/test.txt");<br />

trace(file1.getRelativePath(file2)); // bob/test.txt<br />

The second parameter of the getRelativePath() method, the useDotDot parameter, allows for .. syntax to be<br />

returned in results, to indicate par<strong>en</strong>t directories:<br />

var file1:File = File.docum<strong>en</strong>tsDirectory;<br />

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

var file2:File = File.docum<strong>en</strong>tsDirectory;<br />

file2 = file2.resolvePath("AIR Test/bob/test.txt");<br />

var file3:File = File.docum<strong>en</strong>tsDirectory;<br />

file3 = file3.resolvePath("AIR Test/susan/test.txt");<br />

trace(file2.getRelativePath(file1, true)); // ../..<br />

trace(file3.getRelativePath(file2, true)); // ../../bob/test.txt<br />

Obtaining canonical versions of file names<br />

Adobe AIR 1.0 and later<br />

File and path names are not case s<strong>en</strong>sitive on Windows and Mac OS. In the following, two File objects point to the<br />

same file:<br />

Last updated 6/6/2012<br />

677

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

Saved successfully!

Ooh no, something went wrong!