Adobe AIR and included files

Have you as a developer ever wanted to deploy an Adobe Air application and include files with the installation? Say an XML file for settings and the like? Well, you can include files well enough (to the applicationDirectory), but if you want to write back to that file you’ll get an error. You see, files in the applicationDirectory are read-only.

So what do you do? You’ll need to read that file in the applicationDirectory and then copy it over to the applicationStorageDirectory… or desktopDirectory or even the documentsDirectory. Then you’ll be able to read and write to the file.

The snippet below sets up a reference to a test text document I included in an AIR application. It exists in the protected applicationDirectory. Then the destination (of applicationStorageDirectory) is referenced. If the file doesn’t already exist in the destination location, the one in the applicationDirectory is copied over to the applicationStorageDirectory… and traces “Copy Done” for me.

If you ever wanted to reset the settings file, all you would need to do is to copy over that original included Test.txt file to your applicationStorageDirectory again, over-writing the one that was already there. I didn’t see anything like this in my Google searches, but I did hear of the technique. Here is a little code that shows it in action.

var testFile:File = File.applicationDirectory.resolvePath("Test.txt");

//Copy the file over.

var destination:File = File.applicationStorageDirectory;
destination = destination.resolvePath("Test.txt");

//Only copy the file from the installation bundle if it 
//doesn't exist in the applicationStorageDirectory

if( !destination.exists ){
   if( testFile.copyTo(destination,true)){
      trace("Copy done");

One thing to note – on a Mac, the applicationStorageDirectory exists here: username/Library/Preferences//Local Store/

Of course it exists elsewhere on a PC and Linux, but the applicationStorageDirectory reference takes care of that for you on the different operating systems. You should check your Local Store just to make sure it’s doing what you need it to do.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *

− 1 = three

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>