2 Replies Latest reply: Nov 7, 2014 3:34 PM by Maxijin2 RSS

    File Load is not working on Mac but Windows

    Maxijin2 Community Member

      Hi i'm developing an app which simply load files (images and sounds) and uses binary data. Application is working fine on Windows, but it raises error on Mac.

      Now i dont own Mac so i cant debug it, I also googled but couldnt find anything close to it.

      Please advise

      Thanks

      PS: Its an AIR APP

       

      Here are snippets to understand the code

       

      //browse file
      _loadFile.addEventListener(Event.SELECT, selectHandler);
      _loadFile.browseForOpen(title, typeFilter);
      
      //selectHandler
      _loadFile.addEventListener(Event.COMPLETE, loadCompleteHandler);
      _loadFile.load();
      
      //loadCompleteHandler 
      //works on windows but TypeError on Mac
      
      switch(file.type.toLowerCase()){
      
      
        case ".mp3":
      
        var sound:Sound = new Sound();
        sound.loadCompressedDataFromByteArray(file.data, file.data.length);
        fileHandler(sound);
        break;
      
      
      
        case ".jpg":
        case ".png":
        case ".jpeg":
        case ".gif":
      
         loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadBytesHandler);
        loader.loadBytes(file.data);
        break;
      
        }
      
      
      //loadBytesHandler
      fileHandler(loader.content);
      
      
        • 1. Re: File Load is not working on Mac but Windows
          wadedwalker Community Member

          I just tried a simple File load test and the type property always traces out null. According to the ASDocs, the type property: "On the Macintosh, this property is the four-character file type, which is only used in Mac OS versions prior to Mac OS X. If the FileReference object was not populated, a call to get the value of this property returns null.".

           

          Further reading into the FileReference docs, all properties are supposed to be populated once the complete event fires and that is when I ran a trace of the File.type.


          Since the is an AIR app, you might want to consider using the extension property instead to know the file extension to run a switch case against. The ASDocs also say that in reference to Mac's: "You should consider the creator and type properties to be considered deprecated. They apply to older versions of Mac OS.".

           

          If you choose to use the extension property instead, you don't have to include the "." in your switch statement. The ASDocs do say that "If there is no dot in the filename, the extension is null." So, you may want to run some tests on Windows to make sure that "extension" works. On Mac OS, pretty much every user friendly file (image, movie, document, etc) has a file extension so you shouldn't have any concern of extension returning null on Mac OS.

           

          You probably got the TypeError on Mac OS because you were trying to run a String method on a null object at the start of the switch statement.

           

          FileReference.extension

          • 2. Re: File Load is not working on Mac but Windows
            Maxijin2 Community Member

            Thanks Highly Appreciated