Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I generate a Flex web and Air desktop app from the same source code?

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?

like image 514
Jaymie Thomas Avatar asked Sep 18 '08 15:09

Jaymie Thomas


1 Answers

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.

like image 77
ianmjones Avatar answered Sep 23 '22 14:09

ianmjones