Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1
File Pickers | 99

}
</script>

</head>
<body onload="doLoad( )">

<input id="btnBrowse" type="button" value="Browse" />

</body>
</html>

Browse for a Directory


Problem


Application requirements dictate that you allow users to
select a directory in which they will store data.


Solution


Use theFile.browseForDirectory( )API to prompt the user
to select a directory.


Discussion


TheFile.browseForDirectory( )API creates a native dialog
box that allows users to select a directory. The method takes
a required String argument, which will be used to provide
additional information to the user about the purpose of the
selected directory.


When a directory 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.applicationStorageDirectory;

file.addEventListener( air.Event.SELECT, doSelect );
file.browseForDirectory( "Where do you want to store your
photos?" );

function doSelect( event )
Free download pdf