While working on our upcoming game Mr. Bounce I was searching for a way to compile debug and release builds from the same source in AS3. Our game project includes things like an internal level editor and cheat keys that we need for developing and testing the game, but should not go in the release version of the game.
I stumpled across something called Conditional Compilation on Ryan Taylor s Blog a new feature of the Flex 3 SDK. It allows you to define constants (Booleans, Strings, Numbers or expressions) at compile time, which are globally accessible within the source of your application.
You can define your constants on the command-line with mxmlc, in a Flex Ant Task or using a configuration file. See Adobe s documentation for more information on this.
For our game we defined the debug and release constants in the flex_config.xml file that is located in the Flex 3 SDK folder inside the frameworks folder. Both constants are Booleans using the CONFIG namespace.
CONFIG::debug true CONFIG::release false
Now we can check for the debug and release constants in the source code and execute the correct code for the target build:
private function init():void
{
CONFIG::debug
{
// Only init the level editor for the debug build
initEditor();
}
initGame();
}
We could also specify alternative versions of a function for the different builds:
CONFIG::debug
private function init():void
{
initEditor();
initGame();
}
CONFIG::release
private function init():void
{
initGame();
}


