Using AIRAliases.js
As mentioned earlier, your AIR applications will make frequent and extensive use of the AIR and Flash APIs, resulting in lines like
var fp = new window.runtime.flash.filesystem.File();
To make code easier to type, read, and debug, Adobe has created the AIRAliases.js file. This is a JavaScript document that creates shortcuts to the most commonly used AIR and Flash APIs. You'll find this file in the SDK's frameworks folder.
By using the aliases file, instead of the line as written above, you can just type
var fp = new air.File();
To use AIRAliases.js in any application, you must do two things:
- Include it in your HTML page, as you would any other JavaScript file.
- Include it when you build the application for distribution.
I'll walk you through this in more detail in the next sequence of steps.
To use AIRAliases.js:
-
Begin a new AIR project in your text editor or IDE.
The exact steps for doing so are outlined in Chapter 2 and Chapter 3, "AIR Development Tools." In those two chapters I explain how you'd use a text editor, Aptana Studio, or Dreamweaver for this purpose.
Copy the AIRAliases.js file to the project folder created in step 1.
You'll find AIRAliases.js in the frameworks folder within the SDK folder (created when you installed the SDK following the instructions in Chapter 2).
If you're using Aptana Studio, the AIRAliases.js file is automatically part of the project. You can see it in the project tab on the left side of the application (Figure 4.1).
Figure 4.1 The project tab in Aptana Studio shows what files and folders are part of the project.
Ordinarily I would recommend creating a separate folder in which your JavaScript files, like AIRAliases.js, would be stored. But for this simple example, I won't spend the time doing so.
- Add the following to the head of the main HTML document:
<script src="AIRAliases.js" type="text/javascript"></script>
If you do place the file in a special JavaScript folder, you'll need to change this code accordingly.
Aptana Studio automatically creates a reference to AIRAliases.js in the main HTML file, so you can skip this step, or just update the code to reflect the location of the file in a subdirectory if you chose to go that route.
When you build the final application, be sure to include AIRAliases.js.
If you're building the application using the command-line tools (as demonstrated in Chapter 2), the requisite instruction would be something like (Figure 4.2)
adt -package -storetype pkcs12 -keystore ~/Desktop/AIR/MyCert.pfx AIRAliases.air application.xml index.html AIRAliases.js
Figure 4.2 When building an AIR application using the command-line tool, be sure to include all of the program's required files, like AIRAliases.js.
Aptana Studio automatically includes the file as long as it's listed in the project tab (see Figure 4.1). If you're using Dreamweaver, make sure the file is included in the AIR Application and Installer Settings window (Figure 4.3).
Figure 4.3 In Dreamweaver's AIR Application and Installer Settings window, you can choose which files and folders should be included in the build.