the blog
Back to -Blog

Amethyst 2 - Conditional Compilation for ActionScript

Now more like C#
by Dermot Hogan
Friday 12 April 2013.

One of the nice things about C# is that is has good conditional compilation support. ActionScript does support conditional compilation but the syntax isn’t great. In Amethyst 2 we have implemented a C# like syntax for conditional compilation.

Conditional compilation gives you the ability to exclude or include chunks of code at compile time. So in C#, you could say

if (x) {
// do something
} else {
// do something else
}

This is executed at run time and the code inside the if statement will be run or not depending on whether x is true.

But you can also do this

#if X
// do something
#else
// do something else
#endif

Here, the ‘do something’ code will only be compiled if the X symbol is defined. Otherwise the ‘do something else’ code will be compiled in. In other words, it’s done at compile time not run time.

ActionScript does allow conditional compilation, but the syntax is peculiar to say the least. For example,

CONFIG::debugging {
// debugging code here.
}

and you define the constant in the compiler’s arguments like this

-define=CONFIG::debugging,true

In Amethyst 2, we’ve implemented a scheme similar to C#, but using just #if, #else and #endif and with no arithmetic – just ’is the symbol defined’ or not.

The text not included is greyed out in the Editor:

You set the symbols to be ‘defined’ in the compilation options

Note that the options are configuration dependent, so that you can have code included or excluded for, say, Release or Debug configurations.

Clearly, the #if, etc., syntax isn’t ActionScript and so if you export it to another IDE or use just the basic Adobe compilers you will have problems. However, even allowing for that we still think that it’s much nicer to have the #if syntax rather than something like //#if - and that’s what we’ve used.


This is a preview of the forthcoming version of Amethyst 2 – our ActionScript/Flash IDE for Visual Studio 2012 and 2010. If you buy Amethyst 1.0 for Visual Studio 2010 now you will be entitled to a free update to Amethyst 2 when it is released. See the Amethyst 2012 announcement for more information.

Bookmark and Share   Keywords:  Amethyst 2
© SapphireSteel Software 2014