Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1
Creating a Simple AIR Application with HTML and JavaScript | 33

As you can see, this is a very basic HTML file that displays
“Hello World” and calls a JavaScript function once the file
has loaded and initialized.


There are a couple of lines worth pointing out:


<body onload="init( )">

We just use the standard onload event on the body element
to get an entry point for JavaScript into our application:


<script>
function init( )
{
...
}
</script>

We then use a standard JavaScript function to capture the
onload event.


Accessing AIR APIs


Looking at theinitJavaScript function, you’ll see some code
you may not be familiar with:


runtime.trace("init function called");

This is the only AIR-specific code/markup in the entire appli-
cation. Theruntimeproperty is a property placed on the
windowobject by Adobe AIR which provides an entry point
into the Adobe AIR engine and APIs. Thetracefunction is a
top-level AIR API which takes a string, and prints it out to
the command line (when the application is launched via the
command line).


All access to AIR-specific APIs (including Flash Player APIs)
are accessed from JavaScript via theruntimeproperty. We
will cover this in more detail throughout the rest of the book.

Free download pdf