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.
Tags: compile, Flash Builder 4, mxmlc
This post was written by Andrei Ionescu
Views: 2034











Hi,
great feature, i didn’t know about it, thanks.
I posted a quick translation of your article for french folks here:
http://www.flex-tutorial.fr/2010/03/04/flex-debug-definition-de-variables-a-la-compilation/
Thanks again
Fabien,
http://www.flex-tutorial.fr
Fabien, I’m glad you found it helpful and thank you for linking back to us.
There’s a plugin that automatically creates two constants (“debug” and “release”) and changes the values when you change modes in flash develop (at the tool bar).
It’s simply awesome.
http://www.flashdevelop.org/community/viewtopic.php?f=5&t=3732
It’s called solution config, and there’s an other more complicated one that I don’t use yet.
@psyked_james is this along the lines you mean http://tinyurl.com/ylq748q – conditional compiler blocks?