<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="Badge()">
<fx:Script>
<![CDATA[
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import mx.controls.Alert;
private var _air:Object;
private var _myButton:Button;
private const APPID:String = 'remindme'; // replace with your app id
private const PUBID:String = 'C4FD61F3CC05834EF9A9FA7AFC266F33D620A29D.1'; // replace with your publisher id
private const APPURL:String = 'http://www.learningconcepts.in/airapps/air/rm.air'; // replace with your app url
private const APPRUNTIME:String = '1.5'; // I’m using 1.5 as a minimum requirement for this example
private const AIRSWF:String = 'http://airdownload.adobe.com/air/browserapi/air.swf'; // adobe’s file
public function Badge():void
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, airSwfLoaded);
loader.load(new URLRequest(this.AIRSWF));
//this._myButton = new Button();
//this.addChild(this._myButton);
}
private function airSwfLoaded(e:Event):void
{
this._air = e.target.content;
switch(this._air.getStatus())
{
case 'available':
// install app
this.installApp();
break;
case 'unavailable':
// AIR not supported on this system
break;
case 'installed':
// check if app is installed
this.checkApp();
break;
}
}
private function checkApp():void
{
this._air.getApplicationVersion(this.APPID, this.PUBID, checkAppCallback);
}
private function checkAppCallback(version:String):void
{
if (version == null) // app is not installed
{
this.launchButton.label = "Install";
this.launchButton.addEventListener(MouseEvent.CLICK, installApp);
return;
}
this.launchButton.label = "Launch";
this.launchButton.addEventListener(MouseEvent.CLICK, launchApp);
}
private function installApp(e:Event = null):void
{
this._air.installApplication(this.APPURL, this.APPRUNTIME, new Array());
}
private function launchApp(e:Event):void
{
var args:Array = new Array();
args.push("aaa");
this._air.launchApplication(this.APPID, this.PUBID, args);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button id="launchButton" />
<s:Label id="statusMessage" />
</s:Application>