AS3 Conditional Compilation

From FlashDevelop

Jump to: navigation, search

ActionScript 3 supports conditional compilation and FlashDevelop offers a nice integration of this feature.

Read: Using Conditional Compilation

FlashDevelop default constants

FlashDevelop automatically sets 6 constants:

You may wonder why the timestamp does not contain the time: that's because setting a different value on each compile was causing serious memory leaks when using the Flex Compiler SHell. Maybe that's fixed in Flex 4 SDK, maybe not.

User-defined constants

In the Project Properties, Compiler Options tab, you can populate the "Compiler Constants" list.

Each line should contain a pair: NAMESPACE::variable_name,value with:

Usage example

A Compiler Const can be used as an externally defined constant value or expression:

public const COMPANY:String = CONFIG::companyName;

private function someFunction() {
  if (CONFIG::debug == true) {
    trace("This code only executed in Debug configuration (but still compiled).");
  trace("Built: " + CONFIG::timeStamp);

Or it can also be used to generate different code paths:

private function someFunction() {
  CONFIG::debug {
    trace("This code is NOT compiled in Release configuration");
  trace("This code never executed in Debug configuration - and apparently not even compiled");
private function someFunction() {
  trace("debug version");

private function someFunction() {
  trace("release version");
Personal tools