Marc Hughes


Home
Blog
Twitter
LinkedIn
GitHub
about
I am a developer from a bit west of Boston.

AIR / Browser API example

24 Mar 2008

AIR / Browser API example

The other day I blogged about a wrapper class that I wrote to handle the AIR / Browser integration API.  Below is an example of another class that I wrote that uses that wrapper class.  It's capable of detecting two different AIR applications, installing them, and running them.  It relies on the wrapper class to do all the heavy lifting, but I thought this might be a good example to help people get started.

package com.agileagenda.web
{

import com.roguedevelopment.air.AIRBrowserRuntime;

import com.roguedevelopment.air.AIRBrowserRuntimeEvent;

import flash.events.IOErrorEvent;

public class InstalledApplications

{

public static function get instance() : InstalledApplications

{

if( instance == null ) { _instance = new InstalledApplications(); }

return instance;

}

protected static var instance:InstalledApplications = null;

protected var api:AIRBrowserRuntime;  

protected static const PUBLISHERID:String = "F49A4D8DF78A1FEE7A3BE440DC11BAB18D922274.1";

protected static const TRACKERID:String =  "com.agileagenda.AgileTracker";

protected static const MAINAPPID:String = "com.agileagenda.AgileAgenda";


protected static const AGILEAGENDAINSTALL:String =  "http://www.agileagenda.com/download/AgileAgenda.air";

protected static const AGILETRACKERINSTALL:String = "http://www.agileagenda.com/download/AgileTracker.air";


[Bindablepublic var isReady:Boolean=false;

[Bindablepublic var hasAIR:Boolean;

[Bindablepublic var agileAgendaVersion:String = "";

[Bindablepublic var agileTrackerVersion:String = "";

public function InstalledApplications()

{

  api = new AIRBrowserRuntime();

  api.addEventListener(AIRBrowserRuntimeEvent.READY, onReady );

  api.addEventListener(IOErrorEvent.IOERROR, onAirFail );

  api.load();

}


protected function onAirFail(event:IOErrorEvent) : void

{

  trace( event.text );

}

protected function onReady(event:AIRBrowserRuntimeEvent ) : void

{

  hasAIR = api.getStatus() == 'installed';

  isReady = true;

  api.addEventListener(AIRBrowserRuntimeEvent.APPVERSIONRESULT, onTrackerVersionResult );

  api.getApplicationVersion( TRACKERID, PUBLISHERID );

}

protected function onTrackerVersionResult(event:AIRBrowserRuntimeEvent) : void

{

  trace("Tracker version installed: " + event.detectedVersion );

  agileTrackerVersion = event.detectedVersion

  api.removeEventListener(AIRBrowserRuntimeEvent.APPVERSIONRESULT, onTrackerVersionResult );

  api.addEventListener(AIRBrowserRuntimeEvent.APPVERSIONRESULT, onAppVersionResult );

  api.getApplicationVersion( MAINAPPID, PUBLISHERID );

}

protected function onAppVersionResult(event:AIRBrowserRuntimeEvent ) : void

{

  trace("Application version installed: " + event.detectedVersion );

  agileAgendaVersion  = event.detectedVersion

  api.removeEventListener(AIRBrowserRuntimeEvent.APPVERSIONRESULT, onAppVersionResult );

}

public function launchAgileAgenda( args:Array ) : void

{

  api.launchApplication( MAINAPPID, PUBLISHERID, args );

}


public function launchAgileTracker( args:Array ) : void

{

  api.launchApplication( TRACKERID, PUBLISHERID, args );

}

public function installAgileAgenda(args:Array) : void

{

  api.installApplication(AGILEAGENDAINSTALL, "1.0", args );

}


public function installAgileTracker(args:Array) : void

{

  api.installApplication(AGILETRACKERINSTALL, "1.0", args );

}


}

}