Getting the File URI of a File in an AIR app’s install directory
source link: http://www.mikechambers.com/blog/2008/11/06/getting-the-file-uri-of-a-file-in-an-air-apps-install-directory/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Getting the File URI of a File in an AIR app’s install directory
Thursday, November 6, 2008
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;
trace(fPath);
This will give you an absolute file URI similar to:
file:///Users/mesh/Documents/Flex%20Builder%203/AppName/bin-debug/icon.png
Of course, this is a bit of a hack, and not that efficient (requires two File instances), but it works.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK