Advertisement
Guest User

browser invocation in flex 4

a guest
May 8th, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  3.                xmlns:s="library://ns.adobe.com/flex/spark"
  4.                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="Badge()">
  5.     <fx:Script>
  6.         <![CDATA[
  7.             import flash.display.Loader;
  8.             import flash.display.MovieClip;
  9.             import flash.events.Event;
  10.             import flash.events.MouseEvent;
  11.             import flash.net.URLRequest;
  12.            
  13.             import mx.controls.Alert;
  14.            
  15.             private var _air:Object;
  16.             private var _myButton:Button;
  17.            
  18.             private const APPID:String = 'remindme'; // replace with your app id
  19.             private const PUBID:String = 'C4FD61F3CC05834EF9A9FA7AFC266F33D620A29D.1'; // replace with your publisher id
  20.             private const APPURL:String = 'http://www.learningconcepts.in/airapps/air/rm.air'; // replace with your app url
  21.             private const APPRUNTIME:String = '1.5'; // I’m using 1.5 as a minimum requirement for this example
  22.             private const AIRSWF:String = 'http://airdownload.adobe.com/air/browserapi/air.swf'; // adobe’s file
  23.            
  24.             public function Badge():void
  25.             {
  26.                 var loader:Loader = new Loader();
  27.                 loader.contentLoaderInfo.addEventListener(Event.INIT, airSwfLoaded);
  28.                 loader.load(new URLRequest(this.AIRSWF));
  29.                
  30.                 //this._myButton = new Button();
  31.                 //this.addChild(this._myButton);
  32.             }
  33.            
  34.             private function airSwfLoaded(e:Event):void
  35.             {
  36.                 this._air = e.target.content;
  37.                
  38.                 switch(this._air.getStatus())
  39.                 {
  40.                     case 'available':
  41.                         // install app
  42.                         this.installApp();
  43.                         break;
  44.                     case 'unavailable':
  45.                         // AIR not supported on this system
  46.                         break;
  47.                     case 'installed':
  48.                         // check if app is installed
  49.                         this.checkApp();
  50.                         break;
  51.                 }
  52.             }
  53.            
  54.             private function checkApp():void
  55.             {
  56.                 this._air.getApplicationVersion(this.APPID, this.PUBID, checkAppCallback);
  57.             }
  58.            
  59.             private function checkAppCallback(version:String):void
  60.             {
  61.                 if (version == null) // app is not installed
  62.                 {
  63.                     this.launchButton.label = "Install";
  64.                     this.launchButton.addEventListener(MouseEvent.CLICK, installApp);
  65.                    
  66.                     return;
  67.                 }
  68.                
  69.                 this.launchButton.label = "Launch";
  70.                 this.launchButton.addEventListener(MouseEvent.CLICK, launchApp);
  71.             }
  72.            
  73.             private function installApp(e:Event = null):void
  74.             {
  75.                 this._air.installApplication(this.APPURL, this.APPRUNTIME, new Array());
  76.             }
  77.            
  78.             private function launchApp(e:Event):void
  79.             {
  80.                 var args:Array = new Array();
  81.                 args.push("aaa");
  82.                
  83.                 this._air.launchApplication(this.APPID, this.PUBID, args);
  84.             }
  85.  
  86.         ]]>
  87.     </fx:Script>
  88.     <fx:Declarations>
  89.         <!-- Place non-visual elements (e.g., services, value objects) here -->
  90.     </fx:Declarations>
  91.     <s:Button id="launchButton" />
  92.     <s:Label id="statusMessage" />
  93.    
  94. </s:Application>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement