Dec 1, 2009 0
Flash Tip: Conditional Compiling
Debuging is a craft in it’s own and it’s always helpful to find new tips and tricks. So, I’m writing to post about a new trick for helping us Flash coders debug our sweet, buggy code. Adobe put in a new feature in Flash CS4 called Conditional Compiling and you can read more about it from InsideRIA’s article.
The basic idea is that you can use a compiler constant called CONFIG::Debug to tell the compile when to run some code. If the constant is set to true it’ll be run if it’s set to false then it won’t. Simple, right? Before you start coding you’ll want to go into your Actionscript 3 settings and click on the last tab surprisingly called “Config constants”. Here you can create the constant and set it’s value.
Now that you are all set you you can then use code such as this to see it in action.
1 2 3 4 5 6 7 8 9 | var val:int = 0; for (var i:int = 0; i < 200; i++) { val += i * .5; CONFIG::Debug { trace(val); } } |
And that’s it. It’s a small tip but one that I’ll be definitely using from now on in my projects. If you want to see another simple example I’ve put up a zip file located here for your viewing pleasure.