ActionScript3 preprocessing

If you are familiar with C you know what a preprocessor is. Otherwise you may want to take a look at the blog of Mike Chambers and come back after reading his article on using a preprocessor with ActionScript.

If you read the article of Chambers or know about preprocessors in general you may know that you can not edit and compile the same file that you send through a preprocessor. Chambers does not have this problem because he uses a commandline everytime he compiles his files.

You could have one directory called \bin\ and one \source\ but that is very long-winded. What I need are the benefits of a preprocessor but I just do not want to feel that there is a preprocessor workin in the background.

Therefore I wrote two little applications. Let me explain how it works. My first idea was to substitute the MXMLC (aka Macromedia Flex Compiler). The problem is that the Compiler is deep integrated in the Flex framework and since I do not know anything about Eclipse and that framework stuff I had to throw that idea away.

The next solution that crossed my mind was to have two seperate applications. The first should create a backup of the code and then run the preprocessor. Then the Flex Builder could do his work. After that is done the second application should restore the original sourcecodes. Sounds good - works great.

How to?
First of all you need the cpp preprocessor that Chambers talks about. Google will be your friend. Then download my little package called as3pp. Now follow theese instructions:

Step 05
1.) Unzip to a location that fits into your aesthetic well-being.
2.) Start Flex Builder
3.) Create a new project
4.) Open Project->Properties and switch “Builders”
5.) Create a new Builder and call it “Preprocessor”. The settings should look like in the picture.
On the “Refresh” tab make sure that the following options are checked:
- Refresh resources upon completion.
- The selected source
- Recursively include sub-folders
On the “Build Options” tab make sure that the following options are checked:
- After a “Clean”
- During manual builds
- During auto bulds
- During a “Clean”
Done.
6.) Create another new builder and call it “File Restore”. The settings should be the same that you used for the preprocessor
7.) Arrange the builders in this order

You are done. Make sure to uncheck the “Build Automatically” option in the Project menu. You are done. The preprocessor works for me fine and I will never miss it anymore :o)

Please leave a comment about bugs etc. The as3pp tools should work with win9x/nt systems.

Related Posts

2 Responses to “ActionScript3 preprocessing”


  1. 1 More Flexible Builder

    I have tryed the preprocessor integration but it produces a file with zero length. I used the latest versions of MinGW and Cygwin cpp-preprocessor.

    I also ran the contents of pp0 command manually:
    “cpp -P -include include.h file file”. When the input and output file are the same, the command produces empty file.

    Could you release the source code for pp0 and pp1 (if it is written in c/c++). I also need to add preprocessing for mxml-files.

    Thank you

  2. 2 Chris

    Interesting howto, but where’s the source to as3pp? Are proprocessors really so complicated that you feel the need to keep it closed source?

Leave a Reply






Close
E-mail It