RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Query a Local Database in AIR's Desktop RIA Environment : Page 2

One of the more intriguing features of Adobe Integrated Runtime (AIR) is its database connectivity with a local database. Learn how to leverage this feature in desktop by walking through the development of a database application in AIR.

The AIR Application Structure
When using JavaScript and HTML, a barebones AIR application consists of a manifest (XML) file and an HTML container. For the sake of clarity, I included the JavaScript code in a separate file. So the complete downloadable source code for this application contains these three files:
  • AirQuery.xml: application manifest
  • AirQuery.html: initial application window
  • AirQuery.js: functionality implemented in JavaScript

This project did not require any Flash/ActionScript functionality, but I easily could have incorporated it. You can access ActionScript classes from JavaScript and in turn gain access to the HTML container's DOM, as well as to the JavaScript functions. Marshalling data between JavaScript and ActionScript is not very difficult.

To test the application, copy the above three files (together with AIRAliases.js) to a directory and type adl AirQuery.xml at a command prompt in the directory where you saved the files. ADL is the AIR Debug Launcher, which allows you to run AIR applications without packaging and installing them first. If everything went OK and the application runs, you will see the window in Figure 1.

Click to enlarge

Figure 1. The Main Window at Run Time (AirQuery.html)

The application manifest file, which Adobe calls the application descriptor, tells the runtime a couple of things about the application:

  1. The HTML container where the application should run
  2. How it should be sized

For example, here's the application manifest for this project (AirQuery.xml):

<?xml version="1.0" encoding="UTF-8"?> 
<application xmlns="http://ns.adobe.com/air/application/1.0.M4" appId="AirQuery" version="0.1"> 
	<rootContent systemChrome="standard" 

At runtime, AIR will load the HTML document pointed at by the rootContent element. In this case, the HTML file (AirQuery.html) is very simple. All it does is call the appLoad function in the AirQuery.js file when the onLoad event fires:

	<script src="AIRAliases.js" type="text/javascript" /> 
	<script src="AirQuery.js" type="text/javascript" /> 
	<title>AIR Query</title>
<body onLoad="appLoad();" id="pBody" bgcolor="#ffffcc">
	Type query here:

This HTML file is also the main visual container in which the application runs. However, the runtime can create any windows it needs.

An AIR application built around the HTML model has its own WebKit-based browser environment, which supports JavaScript and HTML rendering. This is the 'browser context' in which the AIR application is running.

The appLoad function is the entry point into the application, and besides painting the screen by inserting into AirQuery.html's DOM, it registers an INVOKE event with the runtime. This is an event of the air.Shell class, which is triggered when the application launches. This class can be used to parse the command line parameters, which is what AirQuery.js does in the event handler (the starting function). If there is a parameter, the application will attempt to open a database by that name; otherwise it will use a default name.

Shell is one of the four system classes of the runtime. Other categories of classes (as defined in the official documentation) are file, events, window, geometry, networking, desktop, service monitoring, media, SQL, and utilities. These classes map to a more complex structure that includes the Flash classes. For example, the full path for the Shell class is window.runtime.flash.systems.Shell. Aliasing defined in AIRAliases.js allows the class to be referenced as air.Shell.

The heterogeneous hierarchy, which includes native AIR classes, Flash classes, and possibly Flex classes, will no doubt be one of the more confusing aspects of working with AIR. This will become apparent later when I discuss creating windows in AIR.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date