views:

323

answers:

1

Is it possible to write code in a Flex application that will only be run in a debug build, or when running through the debugger? Does Flex provide a way to actually remove code entirely from release builds, like C-style #defines?

The app is not necessarily running in a web page.

+7  A: 

You can do conditional compilation like this:

CONFIG::debugging {
    // this will be removed if CONFIG::debugging resolves to false at compile time
}

And then add this to the compiler flags:

-define+=CONFIG::debugging,true

for debug builds, and

-define+=CONFIG::debugging,false

for release builds. CONFIG and debugging can be anything, like MY_AWESOME_NAMESPACE and fooBar, it doesn't matter.

Read more here: Using conditional compilation.

Theo