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

Working with the file system<br />

Wh<strong>en</strong> you specify true for the overwrite parameter of the copyTo() method, all files and folders in an existing target<br />

directory are deleted and replaced with the files and folders in the source directory (ev<strong>en</strong> if the target file does not exist<br />

in the source directory).<br />

The directory that you specify as the newLocation parameter of the copyTo() method specifies the path to the<br />

resulting directory; it does not specify the par<strong>en</strong>t directory that will contain the resulting directory.<br />

For details, see “Copying and moving files” on page 684.<br />

Deleting directory cont<strong>en</strong>ts<br />

Adobe AIR 1.0 and later<br />

The File class includes a deleteDirectory() method and a deleteDirectoryAsync() method. These methods<br />

delete directories, the first working synchronously, the second working asynchronously (see “AIR file basics” on<br />

page 666). Both methods include a deleteDirectoryCont<strong>en</strong>ts parameter (which takes a Boolean value); wh<strong>en</strong> this<br />

parameter is set to true (the default value is false) the call to the method deletes non-empty directories; otherwise,<br />

only empty directories are deleted.<br />

For example, the following code synchronously deletes the AIR Test subdirectory of the user's docum<strong>en</strong>ts directory:<br />

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

directory.deleteDirectory(true);<br />

The following code asynchronously deletes the AIR Test subdirectory of the user's docum<strong>en</strong>ts directory:<br />

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

directory.addEv<strong>en</strong>tList<strong>en</strong>er(Ev<strong>en</strong>t.COMPLETE, completeHandler)<br />

directory.deleteDirectoryAsync(true);<br />

function completeHandler(ev<strong>en</strong>t:Ev<strong>en</strong>t):void {<br />

trace("Deleted.")<br />

}<br />

Also included are the moveToTrash() and moveToTrashAsync() methods, which you can use to move a directory to<br />

the System trash. For details, see “Moving a file to the trash” on page 685.<br />

Working with files<br />

Adobe AIR 1.0 and later<br />

Using the AIR file API, you can add basic file interaction capabilities to your applications. For example, you can read<br />

and write files, copy and delete files, and so on. Since your applications can access the local file system, refer to “AIR<br />

security” on page 1065, if you hav<strong>en</strong>'t already done so.<br />

Note: You can associate a file type with an AIR application (so that double-clicking it op<strong>en</strong>s the application). For details,<br />

see “Managing file associations” on page 886.<br />

Getting file information<br />

Adobe AIR 1.0 and later<br />

The File class includes the following properties that provide information about a file or directory to which a File object<br />

points:<br />

Last updated 6/6/2012<br />

683

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

Saved successfully!

Ooh no, something went wrong!