Is it possible to have multiple custom build configurations in a Flex project for the same ActionScript 3 code-base?
Platform: Flex 3 & Flex 4 Language: AS3
I have inherited a very large code-base written for the Flex3 framework at work.
My company would like to segment the software into "smaller", more "specific" use-cases. There will be some overlap in 开发者_如何转开发features between the different products.
One option would be to copy the code-base into various projects and prune the code for the various use-cases as appropriate. (is that even appropriate?)
However, I would like to avoid that since maintaining the same code duplicated across more than 3 software products would likely be a pain.
Is it possible to create custom build configurations on top of one (1) code-base that compiles only what is needed for that particular product? (I am imagining something akin to #ifdef statements or perhaps build configurations in Visual Studio)
Would moving to git help facilitate that? (We use SVN.)
Any advice would be greatly appreciated.
-Regards
Oliver
You can totally do conditional compilation if you use FlashDevelop.
Linky link: http://www.flashdevelop.org/wikidocs/index.php?title=AS3_Conditional_Compilation
Basically, you type something like this:
CONFIG::mode_a{
foo_mode_a();
}
CONFIG::mode_b{
foo_mode_b();
}
And then in your flashdevelop project settings, properties, project settings, set some compiler constants, "CONFIG::mode_a,true", "CONFIG::mode_b,false". Then foo_mode_a() will get called and foo_mode_b() will not.
There's various ways you can use this (follow the link), but the most powerful is to make it so that code ISN'T EVEN THERE if you put it in a conditional compilation block with the variable set to false in your settings.
ActionScript does not support conditional compilation or multiple build configurations. What you can do is split your code into multiple component libraries. It would be like creating static and dynamic libraries in C/C++. See this article on creating SWC files. A SWC file is an archive file for Flex components and other assets which you would like to share across multiple projects. This way you will not have to maintain multiple copies of the code.
You can do this to get conditional compilation in AS3, but I'm not sure that it's what your after http://www.boostworthy.com/blog/?p=227
After taking a second look at this it doesn't appear to be fully conditional compilation, as stated by the other poster here, I'd also suggest just breaking the library down and using the appropriate parts where needed, maven is good for managing these types of piecewise setup because you can define module with sub-modules (separate flex libraries or flex modules or apps) and all the dependencies and manage it in one place.
http://maven.apache.org/
for flex compilation
http://flexmojos.sonatype.org/
Okay last edit, furthermore using maven allows you to add properties or dependencies conditionally based on the build environment or by passing parameters to specify a particular profile to use during a compilation, this definitely takes some initial setup/learning time but if you have the time to get setup it pays off in the long term.
I lied about the last edit :), was just thinking you can actually pull off the conditional loading of the classes based on the first route and using getClassByAlias but regardless the class would need a reference in the code and therefore will get compiled in to the swf albeit unused under some conditions.
精彩评论