17 Replies Latest reply: Jan 28, 2011 5:10 PM by flexy_flex RSS

    How to launch AIR 2.0 application from browser

    akoyich

      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

        • 1. Re: How to launch AIR 2.0 application from browser
          chris.campbell Adobe Employee

          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

          • 2. Re: How to launch AIR 2.0 application from browser
            akoyich Community Member

            If my publisherID is set to a blank string, how is the badge able to detect if the application is installed on the user's machine? What does it use to detect the installation?

             

            Also, if I set my publisherID to be blank (like this: <publisherID></publisherID>), I get an error when building my AIR file.

            "Error creating AIR file: 105: ERROR, application.publisherID; null"

            • 3. Re: How to launch AIR 2.0 application from browser
              chris.campbell Adobe Employee

              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

              • 4. Re: How to launch AIR 2.0 application from browser
                akoyich Community Member

                Can you possibly provide me with a live, working example in which the badge is actually launching an installed AIR 2.0 application? The badge still continues to say "Install Now" even when I have installed the application.

                • 5. Re: How to launch AIR 2.0 application from browser
                  akoyich Community Member

                  I figured it out. I was passing "" instead of " ". I knew it was my goofy mistake that was preventing proper functionality, but I was hoping for the right light to shine on the problem.

                   

                  Thank you,

                  Alex K

                  • 6. Re: How to launch AIR 2.0 application from browser
                    chris.campbell Adobe Employee

                    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

                    • 7. Re: How to launch AIR 2.0 application from browser
                      akoyich Community Member

                      Actually, I had to have a string that was a space, as a blank string

                      did not work.

                       

                      - Alex

                      • 8. Re: How to launch AIR 2.0 application from browser
                        atian25

                        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...

                        • 9. Re: How to launch AIR 2.0 application from browser
                          chris.campbell Adobe Employee

                          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

                          • 10. Re: How to launch AIR 2.0 application from browser
                            chris.campbell Adobe Employee

                            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

                            • 11. Re: How to launch AIR 2.0 application from browser
                              atian25 Community Member

                              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>
                               
                              
                              • 12. Re: How to launch AIR 2.0 application from browser
                                chris.campbell Adobe Employee

                                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

                                • 13. Re: How to launch AIR 2.0 application from browser
                                  atian25 Community Member

                                  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.

                                  • 14. Re: How to launch AIR 2.0 application from browser
                                    Laurence MacNeill Community Member

                                    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

                                    • 15. Re: How to launch AIR 2.0 application from browser
                                      Laurence MacNeill Community Member

                                      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.

                                      • 16. Re: How to launch AIR 2.0 application from browser
                                        Laurence MacNeill Community Member

                                        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.

                                         

                                         

                                         

                                         

                                        • 17. Re: How to launch AIR 2.0 application from browser
                                          flexy_flex

                                          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

                                                          }

                                                      }