If you're creating a custom AIR badge for a seamless install then you'll need to load the air.swf files from the Adobe Website (http://airdownload.adobe.com/air/browserapi/air.swf) and call methods on the .swf once it has loaded. This is clunky for a few reasons:
1. Loading the .swf in order to call methods requires loading the .swf into the same ApplicationDomain as the badge itself, which is unfamiliar to many developers
2. Once the .swf is loaded you need to call methods from the content property of the Loader used to load the .swf. Since the content property is typed as DisplayObject you'll have to downcast to Object, and then you'll have to call methods without compile-time checking
As a solution to this you can instead define a class that hides all of the clunkiness. The following is an example of such a class. (This is an adaptation of a class I wrote for AIR in Action.)
package com.themorphicgroup.air.utilities {
import flash.display.Loader;
import flash.system.LoaderContext;
import flash.system.ApplicationDomain;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.net.URLRequest;
public class AirBadgeService extends EventDispatcher {
private var _loader:Loader;
private var _service:Object;
public function AirBadgeService() {
_loader = new Loader();
var context:LoaderContext = new LoaderContext();
context.applicationDomain = ApplicationDomain.currentDomain;
_loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
var swf:String = "http://airdownload.adobe.com/air/browserapi/air.swf";
var request:URLRequest = new URLRequest(swf);
_loader.load(request, context);
}
private function initHandler(event:Event):void {
_service = _loader.content;
dispatchEvent(new Event(Event.COMPLETE));
}
public function getStatus():String {
return _service.getStatus();
}
public function getApplicationVersion(applicationId:String,
publisherId:String,
callback:Function):void {
_service.getApplicationVersion(applicationId, publisherId, callback);
}
public function installApplication(url:String,
runtimeVersion:String,
parameters:Array = null):void {
_service.installApplication(url, runtimeVersion, parameters);
}
public function launchApplication(applicationId:String,
publisherId:String,
parameters:Array = null):void {
_service.launchApplication(applicationId, publisherId, parameters);
}
}
}
Then all you have to do is construct an instance of AirBadgeService, listen for the complete event, and call the methods.