This page is an archive of my old blog. Please visit DavidTucker.net for my current blog.
This site is no longer being maintained and commenting is disabled.

AIR Tip 11 – Launching an AIR Application from an AIR Application

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 )




8 Responses to “AIR Tip 11 – Launching an AIR Application from an AIR Application”

  1. Maz says:

    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}

  2. [...] I’ve searched the web for a method of launching another AIR application from an AIR application and the only way was to load a chunk of SWF, like David does here. [...]

  3. qnaguru says:

    Could not get it to work with my own AIR Application(although correct publisherid and applicaiton id was provided), worked only for launching the target app provided for download. What could be the issue?

  4. seth says:

    I don’t know if this thread is still active but i’m wondering if any readers here have gotten detection of an AIR application installation from another AIR application working. I can successfully launch AIR from AIR but the API call to get the installed version in order to determine if it’s installed doesn’t work. From a browser it works fine but from an AIR app. the callback never gets called. Is this by design? If I can launch AIR from AIR seems to me I ought to be able to get the installed version of another AIR application as long as I have the appID and pubID. However the callback never gets called and there’s no error when the API call is initiated from an AIR application.

  5. [...] my next approach was this article by David Tucker: “AIR Tip 11 – Launching an AIR Application from an AIR Application“. It actually described how to launch an AIR application from another application. This is [...]

  6. Rusiru Boralugoda says:

    Thanks for a great tutorial David. But I sort of have a different problem.

    What if I want to run a one mxml component as another application from the main mxml application while the main mxml is running.

    Say, I have an admin panel and a projector screen. I want to project some of the details in the projector screen while admin panel is running. So here there are two applications as the admin panel and the projector.

    I can’t use your method here because the projector it self has different states that change.

  7. Nikola says:

    Hello,

    In general, I have two questions:

    Lets say I have a launcher (air application with buttons) for launching already installed air applications on the same PC.

    1. How to check if an air application is installed? So, If the target application is installed on the system, the corresponding button in the launcher will be enabled, otherwise disabled. How can be possible? What about the air 2.0?

    2. How to launch an applications using the air 2.0?

    Can you please post some examples regarding these probles?

    Thanks in advance,
    Nikola

  8. kb says:

    This seems like a job for NativeProcess as of AIR 2.0.