Hello World in AIR

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:

ADL

The AIR Debug Launcher that you can use from a command line

ADT

The AIR Developer Tool with which you create deployable .air files

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.

  1. Create a new Flex project called HelloWorld in Flash Builder.

  2. 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.

  3. 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.

An empty template of the AIR application

Figure 9-1. An empty template of the AIR application

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.)

Running the HelloWorld application

Figure 9-2. Running the HelloWorld application

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.

Note

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:

  1. Choose ProjectExport 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.

  2. 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.

  3. 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.

  4. Fill out the creation form in Figure 9-3 and name the file testCertificate.p12.

Note

You can purchase a digital certificate from ChosenSecurity, GlobalSign, Thawte, or VeriSign.

  1. 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.

Creating a self-signed certificate

Figure 9-3. Creating a self-signed certificate

Installing the AIR application

Figure 9-4. Installing the AIR application

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.

Note

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.

AIR application folders

Figure 9-5. AIR application folders

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.119.114