96 | Chapter 4: AIR Mini-Cookbook
the user. For this purpose, it may be beneficial to have a class
or global reference to theFile object, and even to reuse it:
<html>
<head>
<title>Browse for a File</title>
<script type="text/javascript" src="AIRAliases.js">
</script>
<script>
var file = null;
function doLoad( )
{
file = air.File.documentsDirectory;
file.addEventListener( air.Event.SELECT, doSelect );
document.getElementById( "btnBrowse" ).
addEventListener( "click", doBrowse );
}
function doBrowse( )
{
var filters = new window.runtime.Array( );
filters.push( new air.FileFilter( "Image Files", "*.jpg" )
);
file.browseForOpen( "Select Photo", filters );
}
function doSelect( event )
{
var elem = document.createElement( "div" );
elem.innerText = file.nativePath;
document.body.appendChild( elem );
}
</script>
</head>
<body onload="doLoad( )">
<input id="btnBrowse" type="button" value="Browse" />
</body>
</html>