Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1

136 | Chapter 4: AIR Mini-Cookbook


<script>
var file = null;

function doComplete( )
{
document.getElementById( "txtProgress" ).style.
visibility = "hidden";
document.getElementById( "txtProgress" ).innerText =
"Uploading... 0%";

document.getElementById( "btnUpload" ).disabled =
null;
}

function doLoad( )
{
file = air.File.documentsDirectory;
file.addEventListener( air.Event.SELECT, doSelect );
file.addEventListener( air.ProgressEvent.PROGRESS,
doProgress );
file.addEventListener( air.Event.COMPLETE, doComplete
);

document.getElementById( "btnUpload" ).
addEventListener( "click", doUpload );
}

function doProgress( event )
{
var loaded = event.bytesLoaded;
var total = event.bytesTotal;
var pct = Math.ceil( ( loaded / total ) * 100 );

document.getElementById( "txtProgress" ).innerText =
"Uploading... " + pct.toString( ) + "%";
}

function doSelect( )
{
var request =
new air.URLRequest( "http://www.ketnerlake.com/work/
watcher/upload.cfm" );

document.getElementById( "btnUpload" ).disabled =
"disabled";
document.getElementById( "txtProgress" ).style.
visibility = "visible";
Free download pdf