07 Jan 2011 @ 10:24 PM 
 

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.

Tags Categories: actionscript, Flex, tips Posted By: Kenneth
Last Edit: 08 Jan 2011 @ 03 24 PM

EmailPermalink
 

Responses to this post » (2 Total)

 
  1. Neil says:

    I have bookmarked this page as a reminder. Do you know how to do this using ANT?

  2. Kenneth Sutherland says:

    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

Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

 


\/ More Options ...
Change Theme...
  • Users » 1
  • Posts/Pages » 45
  • Comments » 54
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight