The AIR SDK is free, so if you are willing to write code in Notepad (or your favorite text editor) and compile and build your applications using command-line tools either directly or hooked up to an IDE of your choice, you can certainly create AIR applications without having to purchase any additional software. In particular, AIR comes with the following tools:
Most likely, you’ll work in the Flash Builder IDE, which includes the AIR project creation wizard. To get familiar with this method, try developing a HelloWorld application.
Create a new Flex project called HelloWorld in Flash Builder.
In the same window where you enter the project name, select the radio button titled “Desktop application (runs in Adobe AIR).” Click the Finish button to see a window similar to Figure 9-1.
Instead of the familiar <mx:Application>
tag, the root tag of
an AIR application is <mx:WindowedApplication>
. Add a line
<mx:Label text="Hello World">
to the code and run this application. Figure 9-2 shows the
results.
The src folder of your Flash Builder project now contains an application descriptor file called HelloWorld-app.xml. Example 9-1 shows a fragment of this file. (If you don’t use Flash Builder, you’ll have to write the file manually.)
Example 9-1. Partial application descriptor file for HelloWorld
<application xmlns="http://ns.adobe.com/air/application/1.5.1"> <!-- The application identifier string, unique to this application. Required. --> <id>HelloWorld</id> <!-- Used as the filename for the application. Required. --> <filename>HelloWorld</filename> <!-- The name that is displayed in the AIR application installer. May have multiple values for each language. See samples or xsd schema file. Optional. --> <name>HelloWorld</name> <!-- An application version designator (such as "v1", "2.5", or "Alpha 1"). Required. --> <version>v1</version>
The namespace that ends with 1.5.1 indicates the minimum required version of the AIR runtime. AIR is forward compatible, however, so an application built in, say, AIR 1.0 can be installed on the machines that have any runtime with a version greater than 1.0.
You may run into an issue while trying to run an AIR application from Flash Builder: it won’t start but doesn’t report any errors either. To fix this issue, make sure that the namespace ends with 1.5.1 or whatever the current version of AIR is that you use.
The application ID must be unique for each installed AIR application
signed by the same
code-signing certificate. Hence using reverse domain notation, like
com.
farata.
HelloWorld
, is
recommended.
To prepare a package for deploying your application:
Choose Project→Export Release Build, just as you would for deploying Flex applications. Flash Builder will offer to create an installer for the application, an AIR file named HelloWorld.air. There is no need to create an HTML wrapper here as with Flex applications.
Press the Next button. Flash Builder displays a window that asks for you to sign this application using a precreated digital certificate or to export to an intermediate file (with the .air name extension) that you can sign later. This second option is useful if, for example, your firm enforces a special secure way of signing applications.
If you don’t have a real digital certificate, click on the Create button to create a self-signed certificate, which is good enough for the development stage of your AIR application.
Fill out the creation form in Figure 9-3 and name the file testCertificate.p12.
You can purchase a digital certificate from ChosenSecurity, GlobalSign, Thawte, or VeriSign.
Click OK to save the file.
You’ll now see a window that specifies what to include in the HelloWorld.air file. This simple example requires only two files: the application descriptor HelloWorld-app.xml and the application file HelloWorld.swf.
Congratulations—you’ve created your first AIR application. Now what? How do users run HelloWorld.air if their computers don’t have Flash Builder? They must download and install the latest version of the AIR runtime (about 15 MB) from http://get.adobe.com/air/.
When this is complete, they double-click on HelloWorld.air to start the installation of the HelloWorld application and see the scary message in Figure 9-4.
Because you used a self-signed certificate, the AIR installer warns the user that the publisher’s identity is unknown. The fact that you’ve entered your name as a publisher is not good enough; some trustworthy agent has to confirm that you are who you say you are. Besides identifying the publisher of the application, digital certificates guarantee that the binary content of the application has not been modified after signing (the checksum mechanism is being used there). Using the .air file is one of the ways to install an AIR application.
You can allow users to install your AIR application from a web page without saving the .air file. Flex SDK has a badge.swf file that supports such seamless installation (of both AIR itself and your application). For details, refer to the Adobe documentation.
The installer extracts the application name from the descriptor, and the installer also has a mechanism to ensure that you won’t replace an AIR application with its older version.
Assuming your user knows the publisher of this application (you), and clicks Install, the installation process continues, and HelloWorld will take its honorable place among other applications installed on the user’s computer. For example, if no settings are changed, on Windows a new HelloWorld.exe application will be installed in the folder C:Program FilesHelloWorld, as shown in Figure 9-5. Double-click on the .air file after this application was installed (the ID and the version were compared), and you’ll see a screen offering to either uninstall the application or run it.
3.142.119.114