3

I have a web application written in Flex and I'm trying to build an AIR application from the same code base using conditional compilation.

In the AIR application, I need to have import statements such as the following: import flash.data.SQLConnection; import flash.filesystem.File; but I cannot have these import statements in the web application because they are AIR only classes.

I thought I could use conditional compilation to overcome this issue but then I read the following on page http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7abd.html: "You cannot use constant Boolean values to conditionalize metadata or import statements."

If that's the case, how can I have common codebase for Flex based web as well as desktop applications? Has anyone solved this conundrum?

Thanks,

Dilip

More on this question after some trials and errors... I have 3 projects in Eclipse for this project... one for web application, one for AIR application and one for the common source code. In the web and AIR project, I point to the common source code. In the common code, I used conditional compilation and it looks like you can do something like the following: CONFIG::desktopMode { import flash.data.SQLConnection; import flash.events.SQLEvent; import flash.events.SQLErrorEvent; import flash.filesystem.File; }

and similar approach to include web or AIR specific functions during compilation. The approach seems to have worked so far!

The only place I have run across issues is in my Cairngorm's model locator. If I put CONFIG::desktopMode around import statements in Cairngorm's model locator, it starts giving "Uncaught exception in compiler" or "1131 classes must not be nested" error. I'm not sure how to address this error!

Dilip

Dilip Shah
  • 287
  • 2
  • 5
  • 17

3 Answers3

2

You can avoid imports referring fully qualified class names in code. This way you can use conditional compilation.

Constantiner
  • 14,231
  • 4
  • 27
  • 34
  • @J_A_X, Agreed. And as for me I'd prefer to extract platform dependent code into separate classes with common interface. And use these classes by interface injecting particular implementation using some dependency injecting container or some other way (as you described in your answer). – Constantiner Jun 10 '11 at 18:50
1

A common 'codebase' isn't really the situation. Your common codebase is the views and such, but from your Flex to your Air application, your business layer changes. For this, I would recommend you create 2 different projects (one for web, the other for air) and have a library project for all common components, classes, whatever, that can be shared between the two.

It's impossible to have a class like you're saying that says 'if flex, only use this code; if air use this one' since the air SDK adds extra functionality and just saying 'import this' won't work because you also need to remove all references to that import which makes it unreadable.

You need to architect your project properly so that you can separate and abstract out most classes so they can be used for both projects, and then within each project have their specific implementation. Using an application framework like Parsley might help you to accomplish this; I know it helped me.

J_A_X
  • 12,857
  • 1
  • 25
  • 31
0

You can always switch to some full preprocessor like M4 and build your program using normal build tools and not the IDE.

Georgi
  • 1