AIR Tip 11 - Launching an AIR Application from an AIR Application

April 1st, 2008

The Browser API that has been covered in AIR Tip 5 and AIR Tip 6 allows you not only to launch an AIR application from the browser, but also from another AIR application.

This tutorial is current for AIR 1.0

Introduction

As stated previously, for any application to be launched via the Browser API, the property allowBrowserInvocation in the application descriptor file must be set to true (this is true for any AIR application whether Flash, Flex, or HTML). This is demonstrated below:

XML:
  1. <allowBrowserInvocation>true</allowBrowserInvocation>

Code Example 1 - Configuration in the Application Descriptor File

After this has been set on the target application (the application that will be launched), you can configure your application that will launch the target application. This application will need to accomplish only two items.

  1. Load the Browser API SWF from the Adobe site.
  2. Call the launchApplication() method and pass it the needed arguments.

Loading the Browser API

Loading the Browser API is achieved by using the Loader class. You will need to listen for when the SWF download is complete and the SWF has been initialized. Once the SWF has been initialized, commands can be called on it.

ACTIONSCRIPT:
  1. private const BROWSERAPI_URL_BASE: String = "http://airdownload.adobe.com/air/browserapi";
  2.  
  3. // Loading the Browser API
  4. public function init():void {
  5.     _loader = new Loader();
  6.     var loaderContext:LoaderContext = new LoaderContext();
  7.     loaderContext.applicationDomain = ApplicationDomain.currentDomain;
  8.     _loader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
  9.     _loader.load(new URLRequest(BROWSERAPI_URL_BASE + "/air.swf"), loaderContext);
  10. }
  11.  
  12. // Listener for when the API is Initialized
  13. private function onInit(e:Event):void {
  14.     _air = e.target.content;
  15.     launchButton.enabled = true;
  16. }

Code Example 2 - Loading thr Browser API

Launching the Application

Launching an AIR application from an AIR application is quite a bit easier than launching an AIR application from the browser, because you do not have to detect if the user has AIR installed. You simply need to call the launchApplication method of the Browser API. For this example, you will need to know the three arguments: the application ID, the publisher ID, and the arguments array.

ACTIONSCRIPT:
  1. // Launching an Application through the Browser API
  2. private function onButtonClicked( event:MouseEvent ):void {
  3.     _air.launchApplication(
  4.         "net.davidtucker.airtips.LaunchApplication1",
  5.         "C3AD24548343F7569498274306102AB328526006.1",
  6.         new Array( "Sample", "Arguments" )
  7.     );
  8. }

Code Example 3 - Launching an Application through the Browser API

To test this functionality, I have included two AIR application (and the respective source code folders) with this tutorial. First, the Target Application (named LaunchApplication1) contains a list which will be populated with all of the arguments that are passed to it (if you are not familiar with arguments and the BrowserInvokeEvent - read AIR Tip 5). Second, the Launcher Application (named LaunchApplication2) can be used to launch any AIR application, but the fields are pre-populated with data for the Target Application.

As always, please let me know if you have any questions.

Sample Applications
Target Application ( Application, Source )
Launcher Application ( Application, Source )

AIR | Comments | Trackback | Del.icio.us | Digg | Technorati Jump to the top of this page

One comment on “AIR Tip 11 - Launching an AIR Application from an AIR Application”

  1. 01

    Hey hey nice tip mate, did not think of that one ; thanks for sharing it.

    But still waiting for other apps launching capability for AIR…

    {Maz}

    Maz at April 2nd, 2008 around 5:27 am
    Jump to the top of this page

Leave a Reply

  •  
  •  
  •  

You can keep track of new comments to this post with the comments feed.

Badges

View David Tucker's profile on LinkedIn
Inside RIA Badge

Community Posts