Cross-operating system issue in Air

“Adobe® AIRâ„¢, formerly code-named Apollo, is a cross-operating system runtime that allows developers to use their existing web development skills to build and deploy rich Internet applications to the desktop.” (link)

So, build an application and never have to worry about the OS? That’s not completely true.

While building our MixAIR application we noticed the drag ‘n drop functionality was not working on a Mac. After some research we discovered there is a little difference in the ’nativePath’ property of a File. To open a file on a mac you have to add the prefix “file://”, otherwise you get an IOError. To check if the OS is a Mac you can use “Capabilities.os”.

You can use the following code the fix this problem:

1
2
3
4
5
6
7
8
9
10
// set prefix for Mac
var prefix:String = (Capabilities.os.search("Mac") >= 0) ? "file://" : "";
   
var dropfiles:Array = e.transferable.dataForFormat(TransferableFormats.FILE_LIST_FORMAT) as Array;
for each (var file:File in dropfiles){
  var loader:Loader = new Loader();
  var u:URLRequest = new URLRequest(prefix+file.nativePath);
  loader.contentLoaderInfo.addEventListener(Event.COMPLETE, [...]);
  loader.load(u);
}

One Response to “Cross-operating system issue in Air”

  1. jankees Says:

    Thats a really annoying error you’ve found there. Have you reported this to adobe? Maybe something for the next release of AIR

Leave a Reply