Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

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

way to understand this is to look at an example. The follow-
ing example registers for aNETWORK_CHANGEevent that is
broadcast by the Shell class:


function onNetworkChange(event)
{
runtime.trace("Network status changed");
}

function onAppLoad( )
{
window.runtime.flash.system.Shell.shell.addEventListener(
window.runtime.flash.events.Event.NETWORK_CHANGE,
onNetworkChange);
}

As you can see from the example, you register for events
broadcast by a class instance by calling theaddEventListener
function on the class instance. This API requires two argu-
ments.


The first argument is the event name of the event being
broadcast. For all AIR and Flash Player APIs, there will be a
constant for the event name, which you can find in the docu-
mentation.


The second argument is a reference to the function that will
handle the event. In this case, the function is named
onNetworkChange. Looking at the function, you can see that it
is passed an argument with information about the event.
Again, all AIR and Flash Player APIs will pass an object to
the event handler function, which provides information
about the event. You can find the exact type of event object
passed to the handler, and the information it provides, by
referencing the API documentation.


Using AIRAliases.js


As the previous examples show, being able to leverage AIR
and Flash Player APIs from directly within JavaScript can be
very powerful. However, because you must reference the

Free download pdf