File Browse for Multiple Files


Within Android, the browseForOpenMultiple method will open up a specific native file selector that will allow you to open multiple files of type Audio, Image, or Video.

Let’s review the code below. The Button with the Browse label will call the button1_click Handler when clicked. Within this function, an instance of File is created with the variable name file. An event listener is added for  FileListEvent.SELECT_MULTIPLE with the responding method of onMultipleFileSelect, and the browseForOpen method is
called. When browseForOpen is called, the Android file selector is launched. This can be seen in Figure 5-8. After selecting the files within the Android file selector, the event is fired and the onMultipleFileSelect method is called. Within this method, the array of files included in the event is looped over—and if the file type is an image, it is added as a new element. The results can be seen in Figure 5-9:

<?xml version=”1.0″ encoding=”utf-8″?>
<s:Application xmlns:fx=”″
import spark.components.Image;
protectedfunction button1_clickHandler(event:MouseEvent):void
var file:File = new File();
privatefunction onMultipleFileSelect(event:FileListEvent):void {
for (var i:int=0; i<event.files.length; i++){
var f:File = event.files[i] as File;
if(f.extension == “jpg”){
var image:Image = new Image();
image.source = f.url;
image.scaleX = .1;
image.scaleY = .1;
<!– Place non-visual elements (e.g., services, value objects) here –>
<s:Button horizontalCenter=”0″ top=”10″ label=”Browse” click=
<s:Label id=”filepath” left=”10″ right=”10″ top=”100″/>
<s:Scroller top=”150″ horizontalCenter=”0″ bottom=”0″>
<s:VGroup id=”holder”/>

Browse for multiple files

Multiple images selected