Adobe AIR Series - Advanced Features

Having covered many of the basics of developing AIR applications, we've discovered it's not all that different from our traditional HTML/JavaScript development workflows. Sure there are some additional considerations regarding the compilation and distribution of our resulting application, but generally our learning curve has been kept in check. This post will introduce some of the more advanced and interesting features of the AIR API.

Since beginning this series on AIR, our goal has always remained the same; to produce desktop quality software using our web development skills. Now that we've worked through the some of the basics, we're able to explore the features of AIR which will allow us to perform tasks not normally available in a web browser.

AIR exposes a number of classes which enable you to access the advanced features of AIR including:

  • File access
  • Working with sound
  • Networking and service monitoring
  • Local SQL database capability
  • Useful utility classes and much more

For a more comprehensive listing of capabilities, the JavaScript Reference for Adobe AIR is a good place to start.

Since file access capabilities are one of the more popular features of AIR, we'll run through a demonstration which involves the output of some simple directory and file names. Our last post demonstrated the use of the onload event of the window object to implement a runtime CSS style. Extend this example but replacing the body of the window.onload event in the scripts/main.js file with the code from Listing 1 below.

var msg = "";

// we'll be working with the user's documents directory
// for Windows, it's 'My Documents'
var docDir = runtime.flash.filesystem.File.documentsDirectory;

// output the actual path to the 'documentsDirectory'
alert( docDir.nativePath );

// get the directory listing in My Documents
var arr_dirList = docDir.getDirectoryListing();

// gather the directory contents
for( var i = 0; i < arr_dirList.length; i++ ) {
    // restrict to just directories
    if( arr_dirList[i].isDirectory ) {
        msg += arr_dirList[i].nativePath + "\n";
    }
}

// show the directory contents
alert( msg );
Listing 1 - Creating a File object

Listing 1 is using the File class which is available via the runtime.flash.filesystem package. By accessing the documentsDirectory property, we can then use the default document directory path on a user's system to interrogate further. For Windows, this would be the My Documents directory located under the current user's Windows profile. The alert statement uses the nativePath property to output a string which represents the path on the user's operating system. AIR exposes other properties which makes it easy to access common directory paths such as the desktop and application specific storage areas. For more information on these properties, check the links at the end of this post. The last couple of lines in Listing 1 retrieve an array of files and directories which are located under the user's document directory. In this case, we're filtering the results returned to only include directories. The resulting output of the alert statements in Listing 1 can be seen in Figures 1 and 2 below.


Figure 1 - documentsDirectory path


Figure 2 - Directory listing dump of the documentsDirectory

This was obviously a small demonstration on the capabilities of AIR, in particular the file access capabilities. Check out the links below for more information on how to implement this and other very useful and interesting features of AIR.

Introduction | Layouts, Styles, and Logic | Advanced Features | Truveo Sample Application

 


Enable the Subscriptions block here!