3 Replies Latest reply on Aug 17, 2010 2:51 PM by swmangold

    AIR app works in windows, not mac/linux

    swmangold Level 1

      Hi All,

      I developed an app and I am having the strangest problem where it works fine in windows, but not on the mac/linux platform.  It's an image manipulation program where the user loads images into the AIR app from their local file system.  Here's the workflow:

      • user clicks button that opens file browser
      • user selects an image file
      • the selected image is loaded onto the stage into a movie clip
      • ..other magical things happen to the image

       

      When I use the app in Windows, I can select an image from the file browser and it's added to the stage.  When using mac/linux, I can select a file, but it is not added to the stage.  Here is code dealing with selecting the image file and loading it onto the stage:

       

      /////  START CODE //////

       

      var selectedImage:File = new File(); //This holds the location of the file that will be selected using the file browser
      controlPanel.select_but.addEventListener(MouseEvent.MOUSE_UP, selectImageFile); //Event listener to open file browser from button press

       

      //This function opens the file browser
      function selectImageFile(e:MouseEvent):void {
         var imgFilter:FileFilter = new FileFilter("Images", "*.png;*.jpg;*.bmp"); //Only show image files
          selectedImage.browseForOpen("Open", [imgFilter]); //Open file browser
          selectedImage.addEventListener(Event.SELECT, fileSelected); //When user selects file, run fileSelected function
      }

       

      //This function passes the location of the selected file to the loadimage function
      function fileSelected(event:Event):void {
          loadImage(selectedImage.nativePath);
      }

       

      var imageLoader:Loader; //Create loader object to hold selected image.  We are using loader because we need to get properties from the loaded clip that are only accessible on the clip is loaded.  loader class allows us to assign event.COMPLETE listener

       

      //Load selected image into loader

      function loadImage(url:String):void {
          imageLoader = new Loader();//Create new loader
          imageLoader.load(new URLRequest(url));//load the selected image

          var imageClip:MovieClip = new MovieClip();//Create movie clip to hold the loader
          imageClip.addChildAt(imageLoader,0); //Place loader into movie clip.  Dont add the movie clip to the stage until the image is loaded
          imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);//add event listener that tells us when image is loaded
      }

       

      //Once image is loaded, add parent clip (imageClip) to stage
      function imageLoaded(e:Event):void {
          clipHolder.addChild(e.target.content.parent.parent as MovieClip);

           //The reason i am using the event.complete listener is because I need to access properties from the loaded clip that can't be accessed until it's loaded.
      }

       

      ///// END CODE ////

       

      ...As I mentioned earlier, this works perfectly in windows, but not mac/linux.  Can anyone offer any insight as to why this may be the case?  One theory that I have is that the imageClip is getting cleaned up before it is getting added to the stage via the imageLoaded function.  Thanks very much for taking a look!

        • 1. Re: AIR app works in windows, not mac/linux
          Romil Mittal Adobe Employee

          Hi,

           

          When you create a new URL request, please check the argument 'url' that you pass and make sure that you provide the scheme (file://) also prefixed with the absolute path.

           

                      imageLoader.load(new URLRequest(url));//load the selected image

           

          That should fix the problem that you are observing on Mac and Linux.

           

          Thanks,

          -romil

          • 2. Re: AIR app works in windows, not mac/linux
            Frank Stokes-Guinan Adobe Employee

            A file's native path is not the same as its url, and passing the native path to APIs that expect urls is not guaranteed to work in all cases or on all platforms.  For example, there are characters allowed in native paths that are not allowed in urls; such characters have to be escaped or url-encoded.  There are assumptions made when parsing a url that are just not valid with native paths.

             

            Try this simple change in your code below:

             

            //This function passes the location of the selected file to the loadimage function
            function fileSelected(event:Event):void {
                loadImage(selectedImage.url);
            }

             

            Hope that helps,

            Frank

            AIR Engineering

            • 3. Re: AIR app works in windows, not mac/linux
              swmangold Level 1

              Thank you both for your very timely and helpful responses.  Frank, your suggestion worked perfectly, I simply replaced nativePath with url and everything is working perfectly in Ubuntu.  Thanks again!