views:

1720

answers:

4

I'm new to Air. I've got an existing Flex 2 application which I'm considering bringing into Flexbuilder 3. My question is can I use the same base application (and source code) to make the Air version, or would I have to maintain to separate code trees: one for the Air version and one for the Flex/SWF version?

+2  A: 

You can use the same.

Brian
+6  A: 

You can't mix both AIR and Flex in the same Flex Builder project, but you can share code. Here's how...

  1. Create a Flex based project as you normally would.
  2. Create a second AIR based project.
  3. In the second application, go to project->properties.
  4. Select the "Flex build path" option.
  5. Under "Source Path" add the folder that contains the source from your first Flex based project.

Now both projects share the code from the flex project.

You need to be careful not to use AIR only API's in code you intend to share between both apps.

Marc Hughes
+4  A: 

The best approach I've found to creating both Flex and AIR applications from the same source, is to use a core library project for almost all code, with separate small projects for the Flex and AIR applications.

There are two key concepts that make this very powerful and maintainable, allowing for not just two applications, but for many "editions" if you're so inclined.

  1. Modules:- If the core application is actually a module (or a module that loads other modules) you'll be able to easily create stub Flex and AIR applications that are basically there to set project properties, reference classes for cross-module communication, and then simply load the core application module with a ModuleLoader.

  2. Factory Objects:- When there are things you want to do on the AIR desktop application that you can't do in the Flex application, or any case where you want something to work differently across applications, a factory object that creates an instance of a project specific class is a great way to do it. for example, you can call your "save" function, which for AIR saves to the file system, but for Flex calls a web service.

    Have a look at Todd Prekaski's excellent Flex DevNet article on Building Flex and Adobe AIR applications from the same code base on how to do this.

Once you've created a Flex Library project where you're going to create your main module, create your Flex and AIR application projects. In the properties of the two application projects add the library project src directory to the Flex Build Path. While in the project settings you'll also need to add the modules to the Flex Modules section, setting the option to optimise for the project.

ianmjones
+1  A: 

You can see how eSoftHead developed enterprise groupware on both web and desktop application with the same codebase by Flex/AIR at http://blog.esofthead.com/develop-application-runs-on-both-desktop-and-web-environments-by-flex-and-air/

Nguyen Phuc Hai