We love choice

Fx{r} is trying to start the Fx{r} Community! Please join our group on Adobe Groups following this link: http://groups.adobe.com/groups/423.
Fx{r} is now on Twitter too. Follow us @ twitter.com/fx_r!
«
»

ActionScript, How to, MXML

How To Create Conditional Compilation Definitions (Conditional Compile Blocks)

Andrei Ionescu | 04.03.10 | 4 Comments

Google Buzz

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.

Share and Enjoy:
  • Twitter
  • Google Buzz
  • LinkedIn
  • Google Bookmarks
  • del.icio.us
  • Digg
  • Sphinn
  • blogmarks
  • Reddit
  • StumbleUpon
  • Facebook
  • DZone
  • FriendFeed
  • Yahoo! Buzz
  • Yahoo! Bookmarks
  • Slashdot
  • MySpace
  • Add to favorites




Tags: , ,

This post was written by Andrei Ionescu

Views: 2379

related

4 Comments

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

:

:


«
»