Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1

100 | Chapter 4: AIR Mini-Cookbook


{
alert( file.nativePath );
}

Auseful property of the event object that is sent to the han-
dler is the target property that contains a reference to the
originatingFileobject. There is nothing returned from the
dialog operation to be assigned to a File object, as the origi-
nating object will now hold a reference to the directory
selected by the user. For this purpose, it may be beneficial to
have a class or global reference to theFileobject, and even
to reuse it:


<html>
<head>

<title>Select Directory</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( )
{
file.browseForDirectory( "Where do you want to put your photos?" );
}

function doSelect( )
{
var elem = document.createElement( "div" );

elem.innerText = file.nativePath;
document.body.appendChild( elem );
}
</script>
Free download pdf