Skip to content

Instantly share code, notes, and snippets.

@tempredirect
Created March 29, 2011 13:33
Show Gist options
  • Save tempredirect/892358 to your computer and use it in GitHub Desktop.
Save tempredirect/892358 to your computer and use it in GitHub Desktop.
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.external.ExternalInterface;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;
public class DetectAirInstall extends Sprite {
var airSWF:Object; // This will be the reference to the main class of air.swf
public function DetectAirInstall() {
loadAirSWF();
}
public function loadAirSWF():void {
var airSWFLoader:Loader = new Loader(); // Used to load the SWF
var loaderContext:LoaderContext = new LoaderContext();
// Used to set the application domain domain
loaderContext.applicationDomain = ApplicationDomain.currentDomain;
airSWFLoader.contentLoaderInfo.addEventListener(Event.INIT, onAirSWFInit);
airSWFLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIoError);
airSWFLoader.load(new URLRequest("http://airdownload.adobe.com/air/browserapi/air.swf"),
loaderContext);
}
function onAirSWFInit(e:Event):void {
airSWF = e.target.content;
var status:String = airSWF.getStatus();
ExternalInterface.call("detectAirStatus", status);
}
function onIoError(e:IOErrorEvent):void{
reportError(e.text);
}
function reportError(message:String){
ExternalInterface.call("detectAirStatus", "error", message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment