The
following diagram illustrates the relationship between the JavaScript environment
and the AIR run-time environment. Although only a single native window
is shown, an AIR application can contain multiple windows. (And
a single window can contain multiple HTMLLoader objects.)
View full size graphic
The JavaScript environment has its own Document and Window
objects. JavaScript code can interact with the AIR run-time environment
through the runtime, nativeWindow, and htmlLoader properties. ActionScript
code can interact with the JavaScript environment through the window
property of an HTMLLoader object, which is a reference to the JavaScript Window object. In addition, both ActionScript and JavaScript objects can listen for events dispatched by both AIR and JavaScript objects.
The
runtime
property
provides access to AIR API classes, allowing you to create new AIR
objects as well as access class (also called static) members. To
access an AIR API, you add the name of the class, with package,
to the
runtime
property. For example, to create
a File object, you would use the statement:
var file = new window.runtime.filesystem.File();
Note:
The AIR SDK provides a JavaScript file,
AIRAliases.js
,
that defines more convenient aliases for the most commonly used
AIR classes. When you import this file, you can use the shorter
form air.Class instead of window.runtime.package.Class. For example,
you could create the File object with
new air.File()
.
The NativeWindow object provides
properties for controlling the desktop window. From within an HTML
page, you can access the containing NativeWindow object with the
window.nativeWindow
property.
The HTMLLoader object provides
properties, methods, and events for controlling how content is loaded
and rendered. From within an HTML page, you can access the parent
HTMLLoader object with the
window.htmlLoader
property.
Important:
Only pages installed as part of an application
have the
htmlLoader
,
nativeWindow
,
or
runtime
properties and only when loaded as the
top-level document. These properties are not added when a document
is loaded into a frame or iframe. (A child document can access these
properties on the parent document as long as it is in the same security
sandbox. For example, a document loaded in a frame could access
the
runtime
property of its parent with
parent.runtime
.)