Adobe Integrated Runtime (AIR) for JavaScript Developers Pocket Reference

(nextflipdebug5) #1

128 | Chapter 4: AIR Mini-Cookbook


You should register for theInvokeEventduring your applica-
tion’s initialization phase, in order to ensure that the event is
captured when the application is initially launched.


You can register for the event from theshell singleton like so:


function init( )
{
air.Shell.shell.addEventListener(air.InvokeEvent.INVOKE,
onInvoke);
}

This registers theonInvokefunction as a handler for the
InvokeEvent. The handler is passed an instance of the
InvokeEvent object, which contains a property named
argumentswhich is anArrayofStringsof any arguments
passed to the application:


function onInvoke(event)
{
air.trace("onInvoke : " + event.arguments);
}

When testing your application via ADL, you can pass in
command line arguments by using the -- argument. For
example:


adl InvokeExample.xml -- foo "bim bam"

This would pass in two arguments to the application “foo”
and “bim bam.”


The complete example follows; it listens for theInvokeEvent,
and prints out to the includedtextareahtml control, as well
as the command line viaair.trace( ):


<html>
<head>

<script src="AIRAliases.js" />
<script type="text/javascript">

function onInvoke(event)
{
air.trace("onInvoke : " + event.arguments);
Free download pdf