开发者

Launching an Air 2.0 Application in an Air 2.0 Application

I've been trying to launch a separate Ai开发者_如何学JAVAr Application through my current Air Application.

Both apps are compiled using the Adobe Air 2.0 SDK.

The methods I have found so far involve passing the Publisher ID in addition to the Application ID, but I believe the Publisher ID became redundant past Air 1.5.3?

Below is my current implementation whic seems to correctly ascertain the Air Application's version number, but when I try to launch it, nothing seems to happen.

private static var _air:Object;
private static var _loader:Loader;

private static var appID:String = "someOtherAirApplication";
private static var pubID:String = NativeApplication.nativeApplication.publisherID;  

public static function loadAir() : void
{
 _loader = new Loader();
 var loaderContext:LoaderContext = new LoaderContext();
 loaderContext.applicationDomain = ApplicationDomain.currentDomain;
 _loader.contentLoaderInfo.addEventListener(Event.INIT,onInit);
 _loader.load(new   URLRequest("http://airdownload.adobe.com/air/browserapi/air.swf"),loaderContext);
}

private static function onInit(event:Event) : void
{
 _air = event.target.content;
        //the pubID argument resolves to and empty string ""   
        _air.getApplicationVersion(appID, pubID, versionDetectCallback);
}

private static function versionDetectCallback(version:String) : void
{
if(version != null)
{
_air.launchApplication(appID,pubID);
}
}

I have changed the app-config.xml (app descriptor) on the application I am trying to load to allow browser invocation.

The version number of the app descriptor of my application I am trying to load is "V1" which the versionDetectCallback seems to pickup. If this is the case I would expect to be able to launch it but this doesn't seem the case.

Any ideas?


It seems the issues I was facing, after finding appropriate documentation, was that my method

_air.launchApplication(appID,pubID);

needed to be called from a user generated event, such as a click handler.

http://livedocs.adobe.com/flex/3/html/help.html?content=distributing_apps_1.html

Also it seems the publisher ID is not a required attribute and an empty string can be passed instead.

EDIT: Added example below.

//This method is called from a user initiated event, in this case a mouse click on a button
private static function versionDetectCallback(event:MouseEvent,version:String) : void
{
    if(version != null)
    {
       _air.launchApplication(appID,pubID);
    }
}


maybe will be better to make second application work as simple Web SWF and include it via SWFLoader?

What is your goal of second AIR application? Why not to use just swf?


I needed to start different AIR desktop applications from a single "Dispatcher" AIR desktop application and I had a hard time to understand how to do it. Trying different solutions didn't work. Finally I found different ways to do it.
The easier way is to use adobe.utils.ProductManager, it was tested on Windows.

Here is the code:

import adobe.utils.ProductManager;
private var pm:ProductManager = new ProductManager("airappinstaller");

private function launchMyApplication(myApplicationID:String):void
    {
        pm.launch("-launch " + myApplicationID);
    }

About MyApplication: It is Flex AIR Application and it has a folder META_INF/AIR; there is a file application.xml

  1. Application ID in the tag "id"
  2. Don't forget to set allowBrowserInvocation = true; the default is false. If you forget, the Application you are trying to launch will never start.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜