For a quick, hands-on illustration
of how Adobe® AIR® works, use these instructions to create and package
a simple SWF file-based AIR “Hello World” application using Adobe®
Flash® Builder.
If you haven’t already done so, download and install Flash Builder.
Also, download and install the most recent version of Adobe AIR,
which is located here: www.adobe.com/go/air.
Create an AIR projectFlash
Builder includes tools to develop and package AIR applications.
You begin to create AIR applications in Flash Builder or Flex
Builder in the same way that you create other Flex-based application
projects: by defining a new project.
Open Flash Builder.
Select File > New > Flex Project.
Enter the project name as AIRHelloWorld.
In Flex, AIR applications are considered an application type.
You have two type options:
Select
Desktop as the application type.
Click Finish to create the project.
AIR projects initially consist of two files: the main MXML file
and an application XML file (known as the application descriptor
file). The latter file specifies application properties.
For more information, see Developing AIR applications with Flash Builder.
Write the AIR application codeTo write the “Hello World” application code, you edit the
application MXML file (AIRHelloWorld.mxml), which is open in the
editor. (If the file isn't open, use the Project Navigator to open
the file.)
Flex AIR applications on the desktop are contained within the
MXML WindowedApplication tag. The MXML WindowedApplication tag creates
a simple window that includes basic window controls such as a title
bar and close button.
Add a title attribute to the WindowedApplication
component, and assign it the value "Hello World":
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
title="Hello World">
</s:WindowedApplication>
Add a Label component to the application (place it inside
the WindowedApplication tag). Set the text property
of the Label component to "Hello AIR", and set
the layout constraints to keep it centered, as shown here:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
title="Hello World">
<s:Label text="Hello AIR" horizontalCenter="0" verticalCenter="0"/>
</s:WindowedApplication>
Add the following style block immediately after the opening
WindowedApplication tag and before the label component tag you just
entered:
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
s|WindowedApplication
{
skinClass:ClassReference("spark.skins.spark.SparkChromeWindowedApplicationSkin");
background-color:#999999;
background-alpha:"0.7";
}
</fx:Style>
These style settings apply to the entire application and render
the window background a slightly transparent gray.
The application code now looks like the following:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
title="Hello World">
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
s|WindowedApplication
{
skinClass:ClassReference("spark.skins.spark.SparkChromeWindowedApplicationSkin");
background-color:#999999;
background-alpha:"0.7";
}
</fx:Style>
<s:Label text="Hello AIR" horizontalCenter="0" verticalCenter="0"/>
</s:WindowedApplication>
Next, you will change some settings in the application descriptor
to allow the application to be transparent:
In the Flex Navigator pane, locate the application
descriptor file in the source directory of the project. If you named
your project AIRHelloWorld, this file is named AIRHelloWorld-app.xml.
Double-click the application descriptor file to edit it in
Flash Builder.
In the XML code, locate the commented lines for the systemChrome and transparent properties
(of the initialWindow property). Remove the comments.
(Remove the "<!--" and "-->" comment
delimiters.)
Set the text value of the systemChrome property
to none, as in the following:
<systemChrome>none</systemChrome>
Set the text value of the transparent property
to true, as in the following:
<transparent>true</transparent>
Save the file.
Test the AIR applicationTo test the application code that you’ve written, run it
in debug mode.
Click the Debug button in
the main toolbar.
You can also select the Run > Debug
> AIRHelloWorld command.
The resulting AIR application
should look like the following example:
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.
Note: If the application does not compile, fix any
syntax or spelling errors that you inadvertently entered into the
code. Errors and warnings are displayed in the Problems view in
Flash Builder.
Package, sign, and run your AIR applicationYou are now ready to package the "Hello World" application
into an AIR file for distribution. An AIR file is an archive file
that contains the application files, which are all of the files
contained in the project’s bin folder. In this simple example, those
files are the SWF and application XML files. You distribute the
AIR package to users who then use it to install the application.
A required step in this process is to digitally sign it.
Ensure that the application has no compilation errors
and runs as expected.
Select Project > Export Release Build.
Check that the AIRHelloWorld project and AIRHelloWorld.mxml
application are listed for project and application.
Select Export as signed AIR package option. Then click Next.
If you have an existing digital certificate, click Browse
to locate and select it.
If you must create a new self-signed digital certificate,
select Create.
Enter the required information and click OK.
Click Finish to generate the AIR package, which is named
AIRHelloWorld.air.
You can now install and run the application from the Project
Navigator in Flash Builder or from the file system by double-clicking
the AIR file.
|
|
|