AS3 Enum preprocessor: progress report

! Warning: this post hasn't been updated in over three years and so may contain out of date information.

AS3 EnumsRecently I have been working on an AIR-based project for an AS3 language preprocessor that adds enumeration (enum) support to the language. Today I’m releasing a web-based demo of the project. It can take an enum definition, parse it and either generate an AS3 “enum” class, or report an error if mistakes have been made in the source. The resultant code can then be imported into FlashBuilder etc, allowing the use of enums, rather than lists of numeric constants, in your code.

Please note that this demo is far from feature complete. Currently it is missing the following features that the final preprocessor will have:

  1. It doesn’t cope with comments in the source. I plan on having the release version handle ASDoc comments in the source, which will be copied to the generated AS3 file.
  2. It doesn’t support import statements, so Java-style enums with class-based parameters can’t be created without hand-editing the resultant code.
  3. It doesn’t yet support the .@ notation for saving the developer from having to repeatedly specify the class name when using an enum as a parameter to another enum (see the example below for more details.)
  4. It doesn’t yet run properly via the command line. I hit a problem here as AIR programs do not run very well from the command line, for the application runs in the background and there doesn’t seem to be any easy way to write to stdout or stderr. These shortcomings prevent it being used as part of an automated build process. I’m anticipating the solution will be to write a (probably Java-based) wrapper that handles running the AIR application via both Ant and the command line.
  5. It doesn’t yet invoke mxmlc to compile the resultant file and thus fully check it for errors (in truth, I’m not sure how I’m going to do this, or even whether it’s really required or not!)

AS3 Enums take the general form:

where [] denotes optional items and <> denotes variable content. A simple enum would take the form:

Where as a more complicated enum would take the form:

As previously mentioned, imports and the .@ notation aren’t yet supported, so the nearest form that will be successfully parsed by the demo (but which won’t compile without a SideOfRoad import being manually added) is:

Please have a play around with it and let me know what you think. If you wish to compile any generated code, please note that you need to download the immutable collections library as well (you can read about these collection classes here)

3 thoughts on “AS3 Enum preprocessor: progress report

  1. I don’t really know much about AS code, but doesn’t it produce quite a lot of code for a simple


    also, can’t I change the value of an enum type by calling function Sex with the same number as something that already exists, or is the only way to call this function from the static consts in which case this can’t happen.

    I guess I need to learn more about AS before I start querying this 🙂

  2. @Rich,

    I agree that the code is too long winded and it doesn’t yet have protection against more being added at runtime. Both points will be addressed before launch.

Comments are closed.