Monday, August 3, 2009

Creating your first Adobe Air Application

Adobe Air is a great extension to the Adobe Flex framework that allows almost anyone to create rich internet applications for the desktop. With Adobe Air the same applications will run on Microsoft Windows, Mac OS X and Linux with pretty much no operating system dependent code. There are some exceptions though but that we will discuss later.

This tutorial is the first part of a tutorial series on how to build a File Manager using Adobe Air's out of the box components. This file manager will have Drag & Drop capabilities, within the file manager itself, to copy or move files between directories. It will have native drag & drop capabilities to copy files from the desktop directly to the file manager. Or the other way around. Finally we will also add a navigational menu to the file manager to demonstrate some more useful out of the box Adobe Air components.

But before we go into all that let's create our first "Hello World" Adobe Air application.

Step 1

Create a new project in Flex Builder but this time select the radio button that says 'Desktop Application'

Depending on how you named your project you will see two files in your project. For example if you named it AirFileManager you will see an AirFileManager.mxml file and a AirFileManager-app.xml. The mxml file is the file where you will put the initial code.
Notice the WindowedApplication top level node that is created. This is the Adobe Air equivalent of the Application component in Flex. The main difference being that a WindowedApplication is not restricted to run in a browser, it runs on a desktop, and provides some extra features.

AirFileManager-app.xml file is an application descriptor file where you will configure certain parameters related to your Adobe Air Application. Parameters like transparency, system chrome, name, filename, copyright, window initial size and icon will be configured in this file.

Step 2

Add the following code:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="" layout="absolute">
<mx:Button label="Click me" click="'I have just created my first Adobe Air App!')"/>

Step 3

Execute the Air app by clicking on the run method.

Congratulations! You have just created & executed your first Adobe Air app. But don't go out to celebrate yet... that was just to break the ice.

Let's make some modifications to the application descriptor.
Notice the systemChrome and transparency property. The systemChrome property tells Adobe Air whether to use the operating system native chrome or not. The transparency property is used to determine if the application window will be transparent or opaque. Note however that transparency is only supported if you set the systemChrome to none. If you set systemChrome to standard the operating system chrome is used and therefore Adobe Air can't support transparency as it is outside its control.
Note that the default value for the systemChrome is standard.

To test this feature add a backgroundAlpha of 0.5 to the WindowedApplication component.
And modify AirFileManager-app.xml to:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="">
<!-- The application identifier string, unique to this application. Required. -->

<!-- Used as the filename for the application. Required. -->

<!-- The name that is displayed in the AIR application installer.
May have multiple values for each language. See samples or xsd schema file. Optional. -->

<!-- An application version designator (such as "v1", "2.5", or "Alpha 1"). Required. -->

<!-- Settings for the application's initial window. Required. -->
<content>[This value will be overwritten by Flex Builder in the output app.xml]</content>

Run the Adobe Air application and see the difference in the application window. It should look transparent now.

Deploying Adobe Air Applications

Now that you have created your first Adobe Air application, you should package it into an AIR file. If you are using Flex Builder:

  1. Right click your project folder and select Export

  2. In the next screen choose Release Build and click Next

  3. If you want to include the source code with your release click on Enable View Source and then click Next.

  4. In this screen you are asked for a digital certificate to include with your Adobe Air application. You can either specify a digital signature provided by a third party like Verisign or Thawte. If you don't have one then click Create to create your own self-signed digital certificate. Although you can can create your own digital certificate, it is not the best option as it doesn't provide assurance to the users that your application is safe or that it hasn't been tampered.

  5. Type your digital certificate password and click next

  6. Select the files you want to include in your package and then click finish.

  7. Your AIR installation package should have been created in the same directory as your project. Use this file to distribute your application.

That will be all for now. In the next part of this tutorial we will start adding the file manager components with which we will create a simple but yet powerful file manager in Adobe Air.

Click here to read the next part of this tutorial

Thursday, July 30, 2009

Adobe Flex: The DisplayObject Blend Mode

The blend mode controls what happens when one display object is on top of another. The default setting in Adobe Flex is that the pixels of a display object override those that are displayed in the background. However you can change this behavior by modifying the blendMode setting. Read the language reference entry for DisplayObject. There you will find a detailed description of each blend mode.
In a nutshell the different blend modes available are:
  • BlendMode.NORMAL

  • BlendMode.LAYER

  • BlendMode.MULTIPLY

  • BlendMode.SCREEN

  • BlendMode.LIGHTEN

  • BlendMode.DARKEN

  • BlendMode.DIFFERENCE

  • BlendMode.DARKEN

  • BlendMode.OVERLAY

  • BlendMode.ADD

  • BlendMode.SUBTRACT

  • BlendMode.INVERT

  • BlendMode.ALPHA

  • BlendMode.ERASE

  • BlendMode.SHADE

Use the following flex code to try the different blend modes:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:core="*" xmlns:mx="" layout="vertical" height="600" width="600" horizontalAlign="left">
<mx:ArrayCollection id="blendModes">
<mx:Object label="Normal" data="normal"/>
<mx:Object label="Layer" data="layer"/>
<mx:Object label="Multiply" data="multiply"/>
<mx:Object label="Screen" data="screen"/>
<mx:Object label="Lighten" data="lighten"/>
<mx:Object label="Darken" data="darken"/>
<mx:Object label="Difference" data="difference"/>
<mx:Object label="Overlay" data="overlay"/>
<mx:Object label="ADD" data="add"/>
<mx:Object label="Subtract" data="subtract"/>
<mx:Object label="Invert" data="invert"/>
<mx:Object label="Alpha" data="alpha"/>
<mx:Object label="Erase" data="erase"/>
<mx:Canvas height="200" width="400">
<mx:VBox height="100" width="100" backgroundColor="{color1.selectedColor}" backgroundAlpha="1" blendMode="{}" />
<mx:VBox height="100" width="100" backgroundColor="{color2.selectedColor}" backgroundAlpha="1" x="50" y="50" blendMode="{}"/>
<mx:Panel title="Blend Modes" layout="horizontal">
<mx:ComboBox id="blendMode1" dataProvider="{blendModes}" />
<mx:ComboBox id="blendMode2" dataProvider="{blendModes}"/>
<mx:Panel title="Colors">
<mx:ColorPicker id="color1"/>
<mx:ColorPicker id="color2" selectedColor="blue"/>

Click here to try the example.