Additional compiler arguments – debug only code
Many times you look something up, do it once and think cool I’ll remember that as it’s simple. Then 1 year later you’ve forgotten the syntax and you can’t find that help/blog page where you learned about it the first time.
Well I needed to add in some debug code that would only be there for debugging, and the last thing I want to do when building a release version is to scan through the code to remove it. So the ideal way is to use a conditional compiler argument.
So in Flashbuilder, under the project properties and then the Flex compiler properties you’ll see something like this
So if you had the following defined, -define=CONFIG::DEBUG,true -define+=CONFIG::SOMETHING_ELSE,false
Then in code you could do the following.
CONFIG::DEBUG
private var test : Boolean;
CONFIG::SOMETHING_ELSE
private function somethingElse() : void
{
}
The variable and function code will only be included if the compiler argument is true. So in the above example if you called the function ‘somethingElse()’ then this would generate a build error as somethingElse() doesn’t exist. Change the argument to true and it will build fine.
[ad name=”ad-1″]
2 Replies to “Additional compiler arguments – debug only code”
I have bookmarked this page as a reminder. Do you know how to do this using ANT?
I’ve not actually used ant with the above, but from what I’ve read this will explain it to you.
http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html