3 Replies Latest reply on Nov 14, 2010 5:34 PM by Flex harUI

    Flex 4.1 won't load AIR 2.0 app...

    Laurence MacNeill Level 1

      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.

       

      One last thing:  My Flex app is being hosted on an HTTPS (secure) website.  Will that cause it not to even try to launch a local AIR app?  Is there something different I need to do when launching a local AIR app from an HTTPS-served Flex app?

       

      Thanks,

      Laurence MacNeill

      Mableton, Georgia, USA

       

       

       

       

       

        • 1. Re: Flex 4.1 won't load AIR 2.0 app...
          Laurence MacNeill Level 1

          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.

          • 2. Re: Flex 4.1 won't load AIR 2.0 app...
            nadeem4n

            Hi,

             

            I have a similar problem. I am trying to instantiate the File class on mouse click event in my flex application. When I embed my swf file inside an html page and run it from my local host server, it gives error # 1014 when trying this line: var fileToUpload:File = new File();

             

            Below is my complete code:

             

            <?xml version="1.0"?>

            <!-- mxml\HellowWorld.mxml -->

            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

             

             

            <mx:Script><![CDATA[

             

            import flash.events.Event;

            import flash.events.EventDispatcher;

            import flash.events.HTTPStatusEvent;

            import flash.events.IOErrorEvent;

            import flash.events.ProgressEvent;

            import flash.events.SecurityErrorEvent;

            import flash.filesystem.File;

            import flash.filesystem.FileMode;

            import flash.filesystem.FileStream;

            import flash.net.URLLoader;

            import flash.net.URLRequest;

            import flash.net.URLRequestMethod;

            import flash.utils.ByteArray;

             

             

             

             

            public function buttonIsClicked(ev:Event):void {

             

            try{

             

            browseFiles(ev);

             

            }

            catch(err:Error){txtMsg.text = "error: " + err.message;}

             

                        }

             

             

             

             

            public function browseFiles(eve:Event):void

            {

                  var fileToUpload:File = new File(); //This line throws error #1014

            }

             

             

             

                ]]></mx:Script>

             

             

                <mx:Panel title="My Application"

                    paddingTop="10"

                    paddingBottom="10"

                    paddingLeft="10"

                    paddingRight="10"

                >

                    <mx:Label id="txtMsg" text="Hello World!" fontWeight="bold" fontSize="24"/>

            <mx:Button id="b1" label="Attach file"

                    click="buttonIsClicked(new MouseEvent(MouseEvent.CLICK));"

                    x="105"

                    y="115"

                />

                </mx:Panel>

            </mx:Application>

             

             

            I have installed adobe AIR runtime as well. Please let me know how can I correct it to make it work. I want to use File object, instead of FileReference as I need to use the FileStream for reading bytes.

             

            Thanks & regards,

            Nadeem

            • 3. Re: Flex 4.1 won't load AIR 2.0 app...
              Flex harUI Adobe Employee

              File is only supported on AIR