Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1

58 | Chapter 3: Working with JavaScript and HTML Within AIR


APIs via the runtime property and the complete API package
path, it can lead to very verbose code.


In order to make it easier to use some of the more common
AIR and Flash Player APIs from within JavaScript, Adobe has
created a JavaScript include file, namedAIRAliases.js. This
file, which can be found in theframeworksdirectory of the
SDK, provides aliases for commonly used APIs to make them
more convenient to use from within JavaScript.


To use the aliases file, copy it from the SDK to your applica-
tion directory (make sure to also package it in your AIR file).
You then include it within your application using the script
tag in each HTML document that you want to leverage the
aliases in.


For example, let’s look at the earlier example that writes a
file to the desktop, but uses the JavaScript aliases provided in
theAIRAliases.jsfile instead of typing out the complete pack-
age paths:


<script src="AIRAliases.js"></script>

<script type="text/javascript">
function writeFile( )
{
var desktop = air.File.desktopDirectory;
var file = desktop.resolve("output.txt");
var fileStream = new air.FileStream( );
fileStream.open(file, air.FileMode.WRITE);
fileStream.writeUTFBytes("Hello World");
fileStream.close( );
}
</script>

First, notice that the code is much less verbose. This is because
instead of having to reference APIs viawindow.runtimeand
then their complete package path, we can use the aliases
within the include file.

Free download pdf