Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conditional compilation in Flex (Actionscript) and import statements

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

like image 593
Dilip Shah Avatar asked Feb 12 '26 05:02

Dilip Shah


2 Answers

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

like image 137
Constantiner Avatar answered Feb 15 '26 12:02

Constantiner


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.

like image 38
J_A_X Avatar answered Feb 15 '26 14:02

J_A_X



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!