Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1
Accessing AIR APIs from JavaScript | 55

Accessing AIR and Flash Player APIs


Most AIR and Flash Player APIs are contained within pack-
ages (similar to how many JavaScript frameworks leverage
namespaces and packages). This helps organize the APIs, and
also reduces the possibility of naming conflicts. When
accessing AIR and Flash Player APIs directly from JavaScript,
you must do so via their complete package path and name.


As discussed earlier, all AIR and Flash Player APIs are made
available via thewindow.runtimeproperty. The runtime prop-
erty is at the root of the runtime environment, and all APIs
are relative to this root.


For example, to access an API which is not contained within
a package, such astrace( )you reference it directly from the
runtime property, like so:


window.runtime.trace("foo");

However, if you want to access an API that is contained
within a package, you must prepend the package path to the
API. For example, to access the amount of memory currently
used by the application, you can call thetotalMemoryFlash
Player property that is in theflash.system.Systemclass. To
call this API from JavaScript:


var mem = window.runtime.flash.system.System.totalMemory;

This also applies when creating new instances of an API class
from within JavaScript:


var file = new window.runtime.flash.filesystem.File( );

This code creates a newFileinstance that can be used to
work with the file system.


Here is a complete example that shows how to write a file
namedoutput.txt to the user’s desktop:


//call a static property
var desktop = window.runtime.flash.filesystem.File.
desktopDirectory;
Free download pdf