File Pickers | 97
Browse for Multiple Files
Problem
An application needs to prompt the user to select multiple
files from the local system using the native dialog.
Solution
Use theFile.browseForOpenMultiple( )API to prompt the
user with a dialog box that will allow them to select multiple
files.
Discussion
The use of theFileclass to open a single file is predomi-
nantly the same as using theFileclass to open multiple files.
In the case of allowing the user to select multiple files, the
appropriate method to use isFile.browseForOpenMultiple( ).
TheFile.browseForOpenMultiple( )method takes the same
two arguments that theFile.browseForOpen( )method takes:
a String to be used in the title of the dialog, and an Array of
FileFilter objects.
Once the user has selected the files from the dialog, the
FileListEvent.SELECT_MULTIPLEwill be broadcast. The event
object that is sent to the handler will be of type
FileListEvent. TheFileListEventclass contains a “files”
property, which will be anArrayofFileobjects representing
the files that the user selected:
var file = air.File.documentsDirectory;
file.addEventListener( air.FileListEvent.SELECT_MULTIPLE,
doSelect );
function doSelect( event )
{
for( var f = 0; f < event.files.length; f++ )
{
...
}
}