Skip navigation
akoyich
Currently Being Moderated

How to launch AIR 2.0 application from browser

Sep 22, 2010 10:03 AM

How do I launch an application built with AIR 2.0 via a browser? I have allowBrowserInvocation set to true, but I do not know how to set my publisherID properly (as publisherID is no longer supported in the app.xml in AIR 2.0). Please help me figure out how I can launch my AIR 2.0 application from a badge in the browser.

 

Thank you,

crazedCoder

 
Replies
  • Chris Campbell
    9,455 posts
    May 4, 2010
    Currently Being Moderated
    Sep 23, 2010 10:04 AM   in reply to akoyich

    Hi,

    You should be able to follow the instructions listed on the Installing and running AIR applications from a web page, but pass in an empty string for the pubID parameter.

     

    Chris

     

    Edit: Corrected link

     
    |
    Mark as:
  • Chris Campbell
    9,455 posts
    May 4, 2010
    Currently Being Moderated
    Sep 23, 2010 3:00 PM   in reply to akoyich

    The badge will use the appID parameter to check for previous installs.  As for the publisherID in the application descriptor file, you'll want to have that commented out if you aren't using it.  Only the badge's pubID parameter should be an empty string.  I've also updated the link above to the correct URL.

     

    Thanks,

    Chris

     
    |
    Mark as:
  • Chris Campbell
    9,455 posts
    May 4, 2010
    Currently Being Moderated
    Sep 24, 2010 2:41 PM   in reply to akoyich

    Hi Alex,

    Glad you got this sorted out!  Just to clarify, it should be an empty "" string, not a string with a space " ".

     

    Thanks,

    Chris

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 29, 2010 7:21 PM   in reply to akoyich

    cant work for me either

     

    and i try another way -  by air.swf

    but it hard code the locallocation :  launchArgs.push("adobe.com" + ":" + lcName, AIR_LC_METHOD_NAME);

    so we cant load air.swf in my web...

     
    |
    Mark as:
  • Chris Campbell
    9,455 posts
    May 4, 2010
    Currently Being Moderated
    Oct 14, 2010 3:22 PM   in reply to akoyich

    Hi Alex,

    Is it possible to get your badge.as code, the application descriptor, and the html files for the badge?  We've been under the impression that it should be an empty string and would like to investigate further if possible.

     

    Please feel free to email me at ccampbel@adobe.com.  If you attach a .zip, please remove the extension so it can get past our email filter.

     

    Thanks,

    Chris

     
    |
    Mark as:
  • Chris Campbell
    9,455 posts
    May 4, 2010
    Currently Being Moderated
    Oct 14, 2010 3:21 PM   in reply to atian25

    atian25 wrote:

     

    cant work for me either

     

    and i try another way -  by air.swf

    but it hard code the locallocation :  launchArgs.push("adobe.com" + ":" + lcName, AIR_LC_METHOD_NAME);

    so we cant load air.swf in my web...

    Hi,

    Would it be possible to get access to your code, where not quite sure what's going on here.  Are you running into problems loading air.swf or having issues with the adobe.com domain?

     

    Thanks,

    Chris

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 14, 2010 7:05 PM   in reply to Chris Campbell

    thanks for reply.

     

    i had try, but i cant get it work.

    could u plz upload a runable project? thanks.

     

    below is my test code and snapshot:

     

    thanks.

     

    snapshot.png

     

    <?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" applicationComplete="initApp(event)">
         <s:layout>
              <s:BasicLayout/>
         </s:layout>
         <fx:Script>
              <![CDATA[
                   import mx.controls.Alert;
                   import mx.events.FlexEvent;
     
                   private var airswf_local:Object;
                   private var airswf_adobe:Object;
                   private var airswf_web:Object;
                   
                   private var appId:String = "elvis.ss7.analysis";
                   private var pubId:String = "86A58DC9C1B96E580EB61C60F1070F0656213B97.1";
                   
                   protected function initApp(e:FlexEvent):void{
                        //load from local
                        var airLoader_local:Loader = new Loader();
                        var context_local:LoaderContext = new LoaderContext();
                        //context.applicationDomain = ApplicationDomain.currentDomain;
                        airLoader_local.contentLoaderInfo.addEventListener(Event.INIT, function(e:Event):void{
                             log.appendText('airLoader_local loaded.\n');
                             airswf_local = e.target.content;
                        });
                        airLoader_local.load(new URLRequest('resources/air.swf'), context_local);
     
                        //load from adobe
                        var airLoader_adobe:Loader = new Loader();
                        var context_adobe:LoaderContext = new LoaderContext();
                        airLoader_adobe.contentLoaderInfo.addEventListener(Event.INIT, function(e:Event):void{
                             log.appendText('airLoader_adobe loaded.\n');
                             airswf_adobe = e.target.content;
                        });
                        airLoader_adobe.load(new URLRequest('http://airdownload.adobe.com/air/browserapi/air.swf'), context_adobe);
                        
                        //load from web
                        var airLoader_web:Loader = new Loader();
                        var context_web:LoaderContext = new LoaderContext();
                        airLoader_web.contentLoaderInfo.addEventListener(Event.INIT, function(e:Event):void{
                             log.appendText('airLoader_web loaded.\n');
                             airswf_web = e.target.content;
                        });
                        airLoader_web.load(new URLRequest('http://172.30.8.11/test/resources/air.swf'), context_web);
                   }
                   
                   protected function clickHandler(e:MouseEvent):void{
                        var btn:Button = e.target as Button;
                        var airswf:Object;
                        switch(btn.id){
                             case 'check_local':
                                  airswf = airswf_local;
                                  break;
                             case 'check_adobe':
                                  airswf = airswf_adobe;
                                  break;
                             case 'check_web':
                                  airswf = airswf_web;
                                  break;
                             default:
                                  log.appendText('Error!no such btn,id='+btn.id);
                        }
                        if(airswf!=null){
                             log.appendText('start '+btn.id+',getApplicationVersion,wait!\n');
                             airswf.getApplicationVersion(appId, pubId, function(version:String):void{
                                  log.appendText('Use '+btn.id+',version:'+version+'!\n');
                             });
                        }
                   }
     
              ]]>
         </fx:Script>
         <s:Button id="check_local" label="check_local" click="clickHandler(event)" enabled="true" x="50" y="12"/>
         <s:Button id="check_adobe" label="check_adobe" click="clickHandler(event)" enabled="true" x="150" y="12"/>
         <s:Button id="check_web" label="check_web" click="clickHandler(event)" enabled="true" x="250" y="12"/>
         <s:TextArea id="log" x="57" y="70" width="476" height="360"/>
    </s:Application>
     
    
     
    |
    Mark as:
  • Chris Campbell
    9,455 posts
    May 4, 2010
    Currently Being Moderated
    Oct 20, 2010 4:17 PM   in reply to atian25

    I talked with our development team and these approaches (local or privately hosted air.swf's) are explicitly not supported and known to fail.  Sorry about that.  If this is important to you, I'd like to recommend adding a feature request on our ideas.adobe.com site and let us know so others can vote.

     

    Thanks,

    Chris

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 20, 2010 5:35 PM   in reply to Chris Campbell

    thanks for reply.

     

    yes. we think it is important, because our application cant connect the internat. just a local web application.

     

    may be the only way to do this is try to use localconnction to do it myself.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 24, 2010 3:34 PM   in reply to atian25

    I'm having a similar problem -- I'm trying to run an AIR 2.0 app from a Flex 4.1 program, and nothing's happening when I use the air.swf's launchApplication method...  I've tried it with both "" and " " for the programID, and I get nothing either way...  Doesn't launch, and doesn't give me any errors.

     

    I know my Application ID is correct and that my AIR app is installed correctly, because I can use the air.swf's getApplicationVersion and it does return the correct version# of my program.  I did not use the air.swf's installApplication method to install the AIR app -- I downloaded and installed the .air file myself, but I would think that shouldn't make a difference.  It obviously got installed correctly, it just won't launch from my Flex app...

     

    So, why won't my Flex 4.1 app launch my AIR 2.0 app?


    =========BEGIN CODE SAMPLE=========

    private var airSWF:Object; // This will be the reference to the main class of air.swf
    private var airSWFLoader:Loader = new Loader(); // Used to load the SWF
    private var loaderContext:LoaderContext = new LoaderContext();
     
    //After my Flex 4.1 program is loaded and I'm at the main screen, I call the following function:

    private function loadAirSWF():void {
         loaderContext.applicationDomain = ApplicationDomain.currentDomain; 
         airSWFLoader.contentLoaderInfo.addEventListener(Event.INIT, onInit);
         airSWFLoader.load(new URLRequest("http://airdownload.adobe.com/air/browserapi/air.swf"), loaderContext);
    }

     

    protected function onInit(e:Event):void {
         airSWF = e.target.content;
    }

     

    //I have code to check and see if airSWF is null or not

    // (not-null means it's ready to go, of course)
    //If airSWF is not null, the following function is called (and yes,

    // I've run the Flex program in Debug mode and it DOES call

    // this function when airSWF is finished loading):

    public function launchMyAirApplication( applicationID:String, publisherID:String , args:Array = null) : void{
         if( args == null ) { args = []; }
         airSWF.launchApplication(applicationID, publisherID, args);
    }

    //Into that launchApplication function above, I'm sending my proper application ID

    // ("com.myDomain.MyAirApp" -- matches exactly what's in the app.xml),
    //and I've tried both "" and " " for the publisherID.  I've tried it with args and without args...

    //  Nothing works...  Just won't launch...

    ==========END CODE SAMPLE==========

     

    I simply cannot figure out why it won't launch.  Everything looks good to me, but it just won't go.  HELP!

     

    Thanks,

    Laurence MacNeill

    Mableton, Georgia, USA

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 24, 2010 3:46 PM   in reply to Laurence MacNeill

    Oh -- one more thing.  My Flex app is coming from an https (secure) web-page.  Does that make a difference?  Is there something I need to do differently to launch an AIR app from my https-secured web-page?

     

    Thanks,

    L.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 24, 2010 7:11 PM   in reply to Laurence MacNeill

    Found the problem.  You have to call the air.swf's launchApplication method from within a user-caused event handler.  It MUST be in response to a mouse-click or keyboard event, and NOT one that was programmatically generated (e.g. you cannot call a function with something like "buttonClickHandler(new MouseEvent(MouseEvent.CLICK));" and expect it to work.)

     

    So -- don't try to launch an external app unless you're doing it from within a function that was called by a user-generated event.  A programmatically-generated event will fail every time, and will give you NO WARNING!  (Nice little "undocumented feature" in air.swf...)

     

    L.

     

     

     

     

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 28, 2011 5:10 PM   in reply to Laurence MacNeill

    For posterity I'll add that it appears you can't call airSWF.launchApplication() from within the version check callback function.  Even if that version check is initiated by a user action.

     

    I was calling airSWF.launchApplication() upon detecting that a version of software existed.  This told me the AIR app existed, ran the launchApplication() function then died silently.

    When I moved launchApplication() to it's own callback (click for example), it worked.

     

     

                private function versionCheckCallback(version:String):void

                {
                    if (version == null)
                    {
                        trace("Not installed.");
                    }
                    else
                    {
                        trace("Version", version, "installed.");

     

                        airSWF.launchApplication(appID, pubID);  <---- FAIL

                    }

                }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points