Local Access URLs in Adobe AIR
Posted At : February 19, 2008 9:00 AM | Posted By : Jeffry Houser
Related Categories: Flex,Professional,AIR
One of the benefits of Adobe AIR, over a browser based application, is that you can have access to the local file system. This question came up on the House of Fusion Flex Coders list; and I thought I'd blog the answer.
I truncated the original question a bit.
I've got an Flex/AIR app which contains a ite db and some photos which will be included in the install package.
I need to open the db file locally [without using a hard coded absolute path]
How might I go about referencing it this file so that it will work both in development, and installed?
Adobe AIR offers two URL schemes for accessing the local file system. Documentation is here.
* app:/: App URLs are relative to the application install directory. This is what the poster would need to access the assets he was distributing with his application.
* app-storage:/: The app-storage URL will get you to the application's storage directory. On a Windows (XP) machine this is under “Documents and Settings/username/applicationdata/”
As an indirect correlation, if you need the absolute paths to the application install directory or the application root directory, you can get them using the File Class.
Somewhere in your ActionScript code, just import the class:
Two static variables exist on the File class, applicationDirectory and applicationStorageDirectory. This code saves them to local variables:
public var appDirectory : String = File.applicationDirectory ;
public var storageDirectory : String = File.applicationStorageDirectory ;
Since these are static properties you do not need to create an instance of the file class to access them. I'm not sure if one method is preferred over the other, as both seem easily transportable between systems and applications.
On Wednesday the 20th, I'll be all over. I'll be speaking to a business group at the Meriden Connecticut Chamber of Commerce in the morning. I'm speaking as part of their Small Business Institute; and will be speaking on the differences between web sites, web applications, and Internet applications.
In the evening, I'm off to the Boston User Group to speak on code reuse between Flex and AIR. This will be my last time giving the presentation before heading off to 360Flex in Atlanta. Are you in Atlanta and want to get together sometime on Saturday -Wednesday let me know.