How to create conditional compilation definitions (Conditional Compile Blocks) | Mana Blog... for all
Mar 14, 2011

If you have a big project you will soon find out that you’ll need to have to versions of the application. One that you work on and one that you need to give it as a release build. On a release build you need to get rid of unwanted things like pre-filed login credentials that you need to have in the development (to rapidly get over login with one click instead of loosing time filing the fields) and that has not to be in the release build.

Here we have Conditional Compile Blocks or Conditional Compilation Definitions. This works like this: you define a variable that is set in the compilation arguments, and depending of theirs values we remove from compilation some unneeded lines of code.

For example in the properties of your Flex project in the Flex Compiler zone you have the following compile arguments:
-locale en_US -define+=CONFIG::development,true

and in code you can use it like this:
CONFIG::development {
// this is a conditional compile block
usernameTextInput.text = "myusername";
passwordTextInput.text = "mypassword";
}

This means the because in the compile arguments we have CONFIG::development,true (which means that CONFIG::development is true) the code lines inside CONFIG::development{ } block will be compiled in the application.

If instead we have CONFIG::development,false (which means CONFIG::development is false) the code lines inside CONFIG::development{ } block will not be compiled.

So, using…

-define+=CONFIG::development,true - the code lines are compiled in
-define+=CONFIG::development,false - the code lines are not compiled in

You can define any conditional compile variable but you need to keep the CONFIG name space, like this:
-define+=CONFIG::myvar,true
-define+=CONFIG::debug,false
-define+=CONFIG::othervar,true
This is it, kind of simple.

You can see the the available arguments for MXML compiler by executing mxmlc -help command or by going here and scrolling down to the mxmlc 3.0 options section.

Source: http://www.flexer.info/2010/03/04/how-to-create-conditional-compilation-definitions-conditional-compile-blocks/

0 comments: