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
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.
Download (15 kb)
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)