AIR Tip 6: This tutorial will walk you through the process of launching an AIR application from the browser and passing arguments into it. This tutorial is current for Adobe AIR Beta 3.
AIR Beta 3 introduced the browser API. This API allows for AIR application to be launched from a web browser, and it also allows for arguments to be passed into the application from the browser.
Setting up Your AIR Application
Applications must set the allowBrowserInvocation value to true to be able to receive events from the Browser API (as illustrated in Code Example 1). Once this value is set, your AIR application will receive a BrowserInvokeEvent [Reference] when it is invoked via the Browser API.
Code Example 1 - Application Descriptor File with Browser Invocation
Knowing the API
The Browser API contains a method, launchApplication, that actually invokes your AIR application [more information]. This application can take three arguments (two of which are required).
Getting Your Publisher ID
The publisherID [Reference] will be the same for each application that is created with a given certificate. This ID can be obtained in two ways:
Creating a Movie to Launch an AIR Application
For a good starting place, you can view the sample install badge that comes with the Adobe AIR SDK. The source for the badge can be found in the src/badge folder. This sample already has the code needed to load the Browser API. This can be seen in Code Example 2.
Code Example 2 - Loading the Browser API (from the Adobe AIR SDK)
The Adobe AIR SDK also contains the code needed to detect if AIR has been installed. We can modify this to display a status message in our custom badge.
Code Example 3 - Detecting AIR (Modified from the Adobe AIR SDK)
You could easily extend this example to also install AIR if it isn't installed (as well as your application), but for this tutorial, we will just launch an application that is already installed. Code Example 4 illustrates how to use the installApplication method to actually launch the application.
Code Example 4 - Detecting AIR (Modified from the Adobe AIR SDK)
Inserting the Launch Badge Into a Page
Code Example 5 shows how to insert this badge into a page using SWFObject. All of the values that are passed to the browser API are passed into the badge with the flashvars that are created with the JavaScript SWFObject method so.addVariable.
For this example, I have passed the applicationID and publisherID into the movie with flashvars, but there might be situations where you don't want to expose all of this information. In those cases, you can hard code these values into your movie.
Code Example 5 - Inserting the Launch Badge Into a Page with SWFObject
Testing the Example
For the sample to work properly, you will need to have the BrowserInvokeEvent Sample AIR Application from AIR Tip 5. You can install this application here.
Exercise Files
Download (15 kb)
Reference
Getting the application and publisher identifiers (Developer Guide)
Checking from a web page if an AIR application is installed (Developer Guide)
Launching an installed AIR application from the browser (Developer Guide)
Loading the air.swf file (Developer Guide)
[...] Deploying Adobe AIR applications seamlessly with the badge install feature Launching an Application from the Browser [...]
[...] SOAP Webservice (AIR Beta 1) AIR Tip 5: Passing Arguments to an Application on Install (AIR Beta 3) AIR Tip 6: Launching an Application from the Browser (AIR Beta 3) AIR Tip 7: Using Command Line Arguments (AIR Beta 3) AIR Tip 8: Serializing Objects [...]
[...] 来源:AIR Tip 6: Launching an Application from the Browser [...]
[...] Launching an Aplication from the Browser [...]
Hi,
I have followed all examples and managed to open my AIR app by clicking on a flash applet in the browser.
I have also managed to call a function of a flash applet, by clicking on another flash applet.
However I was not able to call a function of my AIR app by clicking on a flash applet. Is this even possible?
I am using the following code in the AIR app:
var lc:LocalConnection = new flash.net.LocalConnection();
lc.connect(”myTestConnection”);
and this in the flash applet:
var conn:LocalConnection = new flash.net.LocalConnection();
conn.send(”myTestConnection”, “myTestFunction”);
the same (AIR) code seems to work when in a second applet but not for the AIR desktop application…
[...] Useful links: http://www.davidtucker.net/2008/01/11/air-tip-6-launching-an-application-from-the-browser/ [...]
Hi,
Thanks for the gr8 tutorial, Can you guide me in executing local application (say windows notepad) from adobe AIR application.
I am not finding any source code / help for this on internet.