Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1

92 | Chapter 4: AIR Mini-Cookbook


property will contain a reference to theFileobject the
invoked the browse operation:


var directory = air.File.documentsDirectory;
directory.addEventListener( air.Event.SELECT, doSelect );
directory.browseForDirectory( "Select a directory of
photos:" );

The File.browseForDirectory( ) method takes one argu-
ment, a string representing additional information that will
be placed in the dialog box. This string is not the title of the
dialog as is the case withFile.browseForOpen( ). There is also
no need to specifyFileFilterobjects as the dialog box pre-
sented is specific to directories, and no files will be displayed.


After the user has selected a directory, the registered event
handler will be called. The file reference, whether using a
class/global reference orEvent.target, will now contain the
path to the selected directory. This is where File.
listDirectory( )comes into play as it returns an Array of
File objects for the selected directory (as represented by the
file reference). TheFile.listDirectory( )method takes no
arguments:


var listing = directory.listDirectory( );

The File class can represent both files and directories on the
user’s file system. TheFile.isDirectoryAPI can be used to
determine whether a specific File instance references a file or
a directory.


TIP
See the API documentation for a complete list of data ex-
posed by the File API.

<html>
<head>

<title>Get a Directory Listing</title>
<script type="text/javascript" src="AIRAliases.js">
</script>
Free download pdf