views:

258

answers:

2

In AS3 you can pass a constant to the compiler

-define+=CONFIG::DEBUG,true

And use it for conditional compilation like so:

CONFIG::DEBUG {
   trace("This only gets compiled when debug is true.");
}

I'm looking for something like #ifndef so I can negate the value of debug and use it to conditionally add release code. The only solution I've found so far was in the conditional compilation documentation at adobe and since my debug and release configurations are mutually exclusive I don't like the idea of having both DEBUG and RELEASE constants.

Also, this format works, but I'm assuming that it's running the check at runtime which is not what I want:

if (CONFIG::DEBUG) {
   //debug stuff
}
else {
   //release stuff
}

I also considered doing something like this but it's still not the elegant solution I was hoping for:

-define+=CONFIG::DEBUG,true -define+=CONFIG::RELEASE,!CONFIG::DEBUG

Thanks in advance :)

+2  A: 

Use the if / else construct : the dead code will be removed by the compiler and it will not be tested at runtime. You will have only one version of your code in your swf.

If you are not sure use a decompiler or a dump tool to see what really happens.

http://apparat.googlecode.com/files/dump.zip

http://www.swftools.org/

...

Patrick
Seems reasonable. On the other hand, the Flash/Flex compiler can be _astoundingly stupid_, so as you say, I'd check before using that if performance really matters to you.
aaaidan