Creating your first desktop AIR application with the Flex SDKFor a quick, hands-on illustration of how Adobe® AIR® works, use these instructions to create a simple SWF-based AIR "Hello World" application using the Flex SDK. This tutorial shows how to compile, test, and package an AIR application with the command-line tools provided with the Flex SDK (the Flex SDK includes the AIR SDK). To begin, you must have installed the runtime and set up Adobe® Flex™. This tutorial uses the AMXMLC compiler, the AIR Debug Launcher (ADL), and the AIR Developer Tool (ADT). These programs can be found in the bin directory of the Flex SDK (see Setting up the Flex SDK). Create the AIR application descriptor fileThis section describes how to create the application descriptor, which is an XML file with the following structure: <application xmlns="...">
<id>...</id>
<versionNumber>...</versionNumber>
<filename>…</filename>
<initialWindow>
<content>…</content>
<visible>…</visible>
<width>…</width>
<height>…</height>
</initialWindow>
</application>
This example only sets a few of the possible application properties. For the full set of application properties, which allow you to specify such things as window chrome, window size, transparency, default installation directory, associated file types, and application icons, see AIR application descriptor files Write the application codeNote: SWF-based AIR applications can use a main
class defined either with MXML or with Adobe® ActionScript® 3.0.
This example uses an MXML file to define its main class. The process
for creating an AIR application with a main ActionScript class is similar.
Instead of compiling an MXML file into the SWF file, you compile
the ActionScript class file. When using ActionScript, the main class
must extend flash.display.Sprite.
Like all Flex-based applications, AIR applications built with the Flex framework contain a main MXML file. Desktop AIR applications, use the WindowedApplication component as the root element instead of the Application component. The WindowedApplication component provides properties, methods, and events for controlling your application and its initial window. On platforms and profiles for which AIR doesn’t support multiple windows, continue to use the Application component. The following procedure creates the Hello World application:
The entire application code now looks like the following: <?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" title="Hello World">
<mx:Label text="Hello AIR" horizontalCenter="0" verticalCenter="0"/>
</mx:WindowedApplication>
Compile the applicationBefore you can run and debug the application, compile the MXML code into a SWF file using the amxmlc compiler. The amxmlc compiler can be found in the bin directory of the Flex SDK. If desired, you can set the path environment of your computer to include the Flex SDK bin directory. Setting the path makes it easier to run the utilities on the command line.
Running amxmlc produces HelloWorld.swf, which contains the compiled code of the application. Note: If the application does not compile, fix syntax
or spelling errors. Errors and warnings are displayed in the console
window used to run the amxmlc compiler.
For more information, see Compiling MXML and ActionScript source files for AIR. Test the applicationTo run and test the application from the command line, use the AIR Debug Launcher (ADL) to launch the application using its application descriptor file. (ADL can be found in the bin directory of the Flex SDK.) From the command prompt, enter the following command: adl HelloWorld-app.xml The resulting AIR application looks something like this illustration (the green background is the user's desktop): ![]() Using the horizontalCenter and verticalCenter properties of the Label control, the text is placed in the center of the window. Move or resize the window as you would any other desktop application. For more information, see AIR Debug Launcher (ADL). Create the AIR installation fileWhen your application runs successfully, you can use the ADT utility to package the application into an AIR installation file. An AIR installation file is an archive file that contains all the application files, which you can distribute to your users. You must install Adobe AIR before installing a packaged AIR file. To ensure application security, all AIR installation files must be digitally signed. For development purposes, you can generate a basic, self-signed certificate with ADT or another certificate generation tool. You can also buy a commercial code-signing certificate from a commercial certification authority. When users install a self-signed AIR file, the publisher is displayed as “unknown” during the installation process. This is because a self-signed certificate only guarantees that the AIR file has not been changed since it was created. There is nothing to prevent someone from self-signing a masquerade AIR file and presenting it as your application. For publicly released AIR files, a verifiable, commercial certificate is strongly recommended. For an overview of AIR security issues, see AIR security (for ActionScript developers) or AIR security (for HTML developers). Generate a self-signed certificate and key pair From the command prompt, enter the following command (the
ADT executable can be found in the bin directory
of the Flex SDK): adt –certificate -cn SelfSigned 1024-RSA sampleCert.pfxsamplePassword This example uses the minimum number of attributes that can be set for a certificate. You can use any values for the parameters in italics. The key type must be either 1024-RSA or 2048-RSA (see Digitally signing an AIR file). Create the AIR package From the
command prompt, enter the following command (on a single line): adt -package -storetype pkcs12 -keystore sampleCert.pfx HelloWorld.air HelloWorld-app.xml HelloWorld.swf You will be prompted for the keystore file password. Type the password and press Enter. The password characters are not displayed for security reasons. The HelloWorld.air argument is the AIR file that ADT produces. HelloWorld-app.xml is the application descriptor file. The subsequent arguments are the files used by your application. This example only uses three files, but you can include any number of files and directories. After the AIR package is created, you can install and run the application by double-clicking the package file. You can also type the AIR filename as a command in a shell or command window. For more information, see Packaging a desktop AIR installation file. |
|