Launching external AIR application from the browser


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
    creationComplete="init()" viewSourceURL="srcview/index.html"> 

    <mx:Script>
        <![CDATA[
            private var _air:Object;
            private var _applicationID:String = 'YOUR_APP_ID';
            private var _publisherID:String = 'YOUR_PUBLISHER_ID';
            private var _arguments:String;

            []
            private var _output:String = '';

            private const AIR_DETECTION_URL:String =
                'http://airdownload.adobe.com/air/browserapi/air.swf';

            private function init():void
            {
                _output += 'Detecting AIR Installation...n';

                var loader:Loader = new Loader();
                var loaderContext:LoaderContext = new LoaderContext();
                loaderContext.applicationDomain = ApplicationDomain.currentDomain;
                loader.contentLoaderInfo.addEventListener(Event.INIT, onInit);

                loader.load(new URLRequest(AIR_DETECTION_URL), loaderContext);
            } 

            private function onInit(event:Event):void
            {
                _air = event.target.content;
                switch(_air.getStatus())
                {
                    case "installed" :
                        // AIR is installed and has been detected
                        _output += 'SUCCESS: AIR installation detectedn';
                        stage.addEventListener(MouseEvent.CLICK, onButtonClicked);
                        break;
                    case "available" :
                        // AIR is Available
                        _output += 'SUCCESS: AIR is availablen';
                        break;
                    case "unavailable" :
                        // AIR Not Available
                        _output += 'FAILURE: AIR not available';
                        break;
                }
            } 

            private function onButtonClicked(event:MouseEvent):void
            {
                _air.launchApplication(_applicationID,_publisherID,_arguments);
            }
        ]]>
    </mx:Script>
    <mx:TextArea x="10" y="10" height="178" borderStyle="solid" borderColor="#67696A"
        text="{_output}" width="255"/> 

</mx:Application>

Launch Demo

Useful links:
http://www.davidtucker.net/2008/01/11/air-tip-6-launching-an-application-from-the-browser/

Photoshop CS4

2 Comments


  1. diya
    May 28, 2009 at 10:22 am

    its not working… error is generated at _air.getStatus() statement..

  2. Mariush T.
    May 28, 2009 at 4:33 pm

    Hi diya,
    I tested the code and everything seems to be working.

    I changed the code a little bit. TextArea shows the progress of detecting AIR runtime on your machine. Launch Demo

Leave a comment