Additional compiler arguments – debug only code

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

Compiler Arguments
Example for custom arguments

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”

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.