With all the excitement about CS4 and the major features it brings (3D, the new timeline and so on), some less ‘shiny’ improvements tend to be overlooked.
Such is the case with conditional compilation. Developers familiar with “real” compilers will instantly know its power.
Conditional compilation allows for blocks of code to be compiled or not based on constants declared in the IDE. In the simplest form, think of it as of a more advanced version of the old “Omit Trace Actions” Publishing option. It allows the developer to optimize the generated code depending on the target medium (e.g. Web vs AIR) or the development phase (i.e. when compiling an app for debugging, the developer may want to switch on more warning traces or display additional info on screen).
The syntax for conditional compilation is dead simple:
function conditionals():void { CONFIG::DEBUG { trace('Debug mode is on'); } }
You need to define the CONFIG::DEBUG
constant in Flash CS4 publishing options.
The example above is very simple, and you may think you could achieve the same thing by defining a const DEBUG:Booolean
in your code and then testing for its value with an if
statement. The conditional compilation however increases performance by not performing the test at runtime and results in a smaller code, since potentially big chunks of code won’t be included at all in the compiled code.
Oh, and you can now specify the execution timeout (previously available only in Flex).
Happy coding!
PS: I can’t wait to test the performance gains with the new Vector class vs the plain Array. My flash chess should get a speed boost, allowing for more features.
4 Responses
yes!!! that’s great news.
this is good! i’ll try using flash cs4
If only it worked in Flex Builder!
Works fine in Flex.
Use this compiler option flag:
-define=CONFIG::FLASH_AUTHORING,true
See “Using Conditional Compilation”
http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html
Comments are closed.