Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1
File Pickers | 95

TIP
If you want to use theFileFilterobject, you must use
the Array class from the Flash runtime, not the JavaS-
cript Array class.

None of the browse methods on theFileclass are static, and
as such, an existing reference to a valid File object must first
be available. The directory represented by thatFileobject
reference will be selected by default when the dialog is dis-
played:


var file = air.File.documentsDirectory;
var filters = new window.runtime.Array( );

filters.push( new FileFilter( "Image Files", "*.jpg" ) );
file.browseForOpen( file, filters );

When a file selection has been made, Adobe AIR will raise an
event in the issuing application. In order to catch that event,
the application must have first registered an event listener.
The event that gets raised isEvent.SELECT, and an Event
object will be passed to the handler:


var file = air.File.documentsDirectory;
var filters = new window.runtime.Array( );

filters.push( new air.FileFilter( "Image Files", "*.jpg" )
);

file.addEventListener( air.Event.SELECT, doSelect );
file.browseForOpen( file, filters );

function doSelect( event )
{
alert( file.nativePath );
}

Auseful property of theEventobject that is sent to the han-
dler is the “target,” which contains a reference to the origi-
natingFileobject. There is nothing returned from the dialog
operation to be assigned to aFileobject, as the originating
object will now hold a reference to the directory selected by

Free download pdf