Loading external files with Adobe AIR

When creating Adobe AIR applications, you have the option of compiling resources into the output file. Accessing the location of the file in AIR can be slightly tricky however, and is not as simple as it is in Flash Player when run locally. To access a local file in Flash Player, you can normally make a new URLRequest() to the location of the file and it will work. In AIR, you have to use the File.as class to access the file location relative to a location within the operating system. While researching this topic, the first Google result was a post by Erik Phansen who wrote about the


method, and how it returns a location relative to the users Documents folder on their machine as a String. However, we think there is a more useful method which is


which returns a path relative to the location of the deployed application. For example, you can use TweenMax library to load in multiple items easily, using the following code:

var file:File = File.applicationDirectory.resolvePath("AppData.xml");
queue = new LoaderMax({name:"xmlQueue", onProgress:XMLprogressHandler, onComplete:XMLcompleteHandler, onError:XMLerrorHandler});
queue.append( new XMLLoader(file.url, {name:"appData"}) );

You need to write the missing event handlers, but you can easily add multiple items to the queue to extend it. This is great for creating AIR applications where you want to have text, images, video or other configuration that needs to be easily be adjusted post compilation.

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on RedditShare on StumbleUponShare on TumblrEmail this to someone

One thought on “Loading external files with Adobe AIR

  1. Just a small important note for those developing using FlashDevelop , to access assets using the File.applicationDirectory method, these files need to be placed inside the /bin folder.
    For example, if you want to get the file “xml_files/AppData.xml”, you need to place the file in your “bin/xml_files/” folder.

Leave a Reply

Your email address will not be published.