13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

AIR application invocation and termination<br />

Wh<strong>en</strong>ever an AIR application is invoked, AIR dispatches an InvokeEv<strong>en</strong>t object of type invoke through the singleton<br />

NativeApplication object. To allow an application time to initialize itself and register an ev<strong>en</strong>t list<strong>en</strong>er, invoke ev<strong>en</strong>ts<br />

are queued instead of discarded. As soon as a list<strong>en</strong>er is registered, all the queued ev<strong>en</strong>ts are delivered.<br />

Note: Wh<strong>en</strong> an application is invoked using the browser invocation feature, the NativeApplication object only dispatches<br />

an invoke ev<strong>en</strong>t if the application is not already running.<br />

To receive invoke ev<strong>en</strong>ts, call the addEv<strong>en</strong>tList<strong>en</strong>er() method of the NativeApplication object<br />

(NativeApplication.nativeApplication). Wh<strong>en</strong> an ev<strong>en</strong>t list<strong>en</strong>er registers for an invoke ev<strong>en</strong>t, it also receives<br />

all invoke ev<strong>en</strong>ts that occurred before the registration. Queued invoke ev<strong>en</strong>ts are dispatched one at a time on a short<br />

interval after the call to addEv<strong>en</strong>tList<strong>en</strong>er() returns. If a new invoke ev<strong>en</strong>t occurs during this process, it may be<br />

dispatched before one or more of the queued ev<strong>en</strong>ts. This ev<strong>en</strong>t queuing allows you to handle any invoke ev<strong>en</strong>ts that<br />

have occurred before your initialization code executes. Keep in mind that if you add an ev<strong>en</strong>t list<strong>en</strong>er later in execution<br />

(after application initialization), it will still receive all invoke ev<strong>en</strong>ts that have occurred since the application started.<br />

Only one instance of an AIR application is started. Wh<strong>en</strong> an already running application is invoked again, AIR<br />

dispatches a new invoke ev<strong>en</strong>t to the running instance. It is the responsibility of an AIR application to respond to an<br />

invoke ev<strong>en</strong>t and take the appropriate action (such as op<strong>en</strong>ing a new docum<strong>en</strong>t window).<br />

An InvokeEv<strong>en</strong>t object contains any argum<strong>en</strong>ts passed to the application, as well as the directory from which the<br />

application has be<strong>en</strong> invoked. If the application was invoked because of a file-type association, th<strong>en</strong> the full path to the<br />

file is included in the command line argum<strong>en</strong>ts. Likewise, if the application was invoked because of an application<br />

update, the full path to the update AIR file is provided.<br />

Wh<strong>en</strong> multiple files are op<strong>en</strong>ed in one operation a single InvokeEv<strong>en</strong>t object is dispatched on Mac OS X. Each file is<br />

included in the argum<strong>en</strong>ts array. On Windows and Linux, a separate InvokeEv<strong>en</strong>t object is dispatched for each file.<br />

Your application can handle invoke ev<strong>en</strong>ts by registering a list<strong>en</strong>er with its NativeApplication object:<br />

NativeApplication.nativeApplication.addEv<strong>en</strong>tList<strong>en</strong>er(InvokeEv<strong>en</strong>t.INVOKE, onInvokeEv<strong>en</strong>t);<br />

And defining an ev<strong>en</strong>t list<strong>en</strong>er:<br />

var argum<strong>en</strong>ts:Array;<br />

var curr<strong>en</strong>tDir:File;<br />

public function onInvokeEv<strong>en</strong>t(invocation:InvokeEv<strong>en</strong>t):void {<br />

argum<strong>en</strong>ts = invocation.argum<strong>en</strong>ts;<br />

curr<strong>en</strong>tDir = invocation.curr<strong>en</strong>tDirectory;<br />

}<br />

Capturing command line argum<strong>en</strong>ts<br />

Adobe AIR 1.0 and later<br />

The command line argum<strong>en</strong>ts associated with the invocation of an AIR application are delivered in the InvokeEv<strong>en</strong>t<br />

object dispatched by the NativeApplication object. The InvokeEv<strong>en</strong>t argum<strong>en</strong>ts property contains an array of the<br />

argum<strong>en</strong>ts passed by the operating system wh<strong>en</strong> an AIR application is invoked. If the argum<strong>en</strong>ts contain relative file<br />

paths, you can typically resolve the paths using the curr<strong>en</strong>tDirectory property.<br />

The argum<strong>en</strong>ts passed to an AIR program are treated as white-space delimited strings, unless <strong>en</strong>closed in double<br />

quotes:<br />

Last updated 6/6/2012<br />

878

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!