Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

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

For example, this reduces:


var desktop = window.runtime.flash.filesystem.File.
desktopDirectory;

to:


var desktop = air.File.desktopDirectory;

Second, the AIR and Flash Player APIs are placed in a
namespace calledair. If you open theAIRAliases.jsfile, you
can see how the aliases actually work. For example, here is
the code that sets up the File API aliases:


var air; if (!air) air = {};

// file
air.File = window.runtime.flash.filesystem.File;
air.FileStream = window.runtime.flash.filesystem.
FileStream;
air.FileMode = window.runtime.flash.filesystem.FileMode;

To see a complete list of APIs included, open up the
AIRAliases.jsfile with a text editor. While not all APIs are
included, you can easily add additional APIs by following the
existing examples in the file.


Leveraging Compiled ActionScript Libraries


Not only can AIR applications leverage Flash Player APIs
directly from JavaScript, they can also access compiled
ActionScript 3 libraries from within JavaScript.


In addition to loading external JavaScript files, the HTML
script tag within an AIR application also has support for
loading compiled ActionScript 3 libraries and providing
access to the ActionScript classes included within the file.
Once the SWF is loaded, the APIs can be referenced in the
same manner as the AIR and Flash Player APIs are referenced
via the API package path and API name.

Free download pdf