mike chambers | about

Getting the File URI of a File in an AIR app's install directory

I am currently working on some code that runs in Adobe AIR where I need to access the File URL file:/ of a file located in the AIR app’s install directory.

Normally, you could get the URI, by accessing the url property of the File object which will return a well formed, absolute file:/ URL. However, this doesn’t work for files located in the AIR app’s install directory.

var f:File = new File("app:/icon.png");
trace(f.url); //app:/icon.png

While the app:/ URI will work within your AIR application, it will not work if you need to pass that URI to a non AIR application.

Here is the workaround for how to get the File URL of a file in the application install directory:

var fPath:String = new File(new File("app:/icon.png").nativePath).url;

This will give you an absolute file URI similar to:


Of course, this is a bit of a hack, and not that efficient (requires two File instances), but it works.

twitter github flickr behance