Accessibility

Adobe AIR article

 

Building Flex and Adobe AIR applications from the same code base


Todd Prekaski

Todd Prekaski

Simplified Chaos

Table of Contents

Created:
29 October 2007
Modified:
25 December 2007
User Level:
Intermediate
Products:
Adobe AIR
Flex

Adobe Flash Player and Adobe AIR provide the ability to run full-featured rich Internet applications (RIAs) either inside a web browser or as native desktop applications on both Windows and Mac OS X, with desktop Linux support coming sometime after the release of Adobe AIR 1.0. The problem for those who want to develop applications that support both desktop and web runtime environments is that Adobe AIR includes extra APIs that allow for local file access, SQLite database support, native windows, and more. These APIs won't compile into a traditional Flex web-based application destined for web-browser distribution (SWF files that you place on a web server and run inside the browser).

In this article, I'm going to show you a technique to set up your Flex Builder 3 workspace and organize your code to output both a Flex web and desktop Adobe AIR application from the same code base. This technique enables you to create a single maintainable code base that will give you web and Adobe AIR applications from your Flex Builder workspace. To demonstrate this, I will set up three projects: one for Adobe AIR, one for the web, and one for the common code. The web and desktop applications will then make calls against an interface that is defined in a common project, but has concrete implementations in each of the desktop and web projects, allowing the desktop version to use the new functionality of Adobe AIR, and giving the developer the option to support a different implementation for the web-based application.

With this knowledge, you'll be able to write software for both a rich browser experience and a desktop application from a code base that doesn't have a bunch of duplicate code. In doing this, you could offer both an online demo with crippled functionality and a desktop version of the application that can run offline with more advanced functionality.

Requirements

In order to make the most of this article, you need the following software and files:

Adobe Flex Builder 3 (includes the Flex 3 SDK)

Adobe AIR

Sample files:

Prerequisite knowledge

This article assumes intermediate to advanced knowledge of Flex, ActionScript 3.0, and MXML. You should know how to create Adobe AIR and Flex projects in Flex Builder 3, and be comfortable with a few object-oriented concepts such as inheritance and interfaces, as well as a splash of UML 2.0.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

About the author

Todd Prekaski has been building software since 1993 (not counting his youthful days programming an Apple IIc and TRS-80). He's been developing applications for web-based startups and Fortune 100/500 enterprises ever since, using several technologies and platforms (including Java and .NET). More recently, he started working with Flex and Adobe AIR, thinking it's going to be the Visual Basic of RIA application development. You can read his occasional technology rant at www.simplifiedchaos.com.