I don’t know how many of you had used Flex Builder 1.0… It wasn’t Eclipse-based. It was based on the award-winning Dreamweaver C++ codebase. We all know that the compiler has been Java-based since day one, so it’s somewhat difficult to integrate the compiler with the C++ based FB (what JNI??). Anyhow, if I remember correctly (and Heidi can correct me if I’m wrong), FB1 launches the mxmlc executable out-of-process in order to compile. There are some drawbacks with this approach. Obviously, the first one is the JVM launch time. Also, compiler error messages go to stderr - FB1 has to parse the messages in stderr. To make matter worse, there are subtle formatting differences in the error messages that makes parsing and tabulating them in FB1 somewhat challenging.
So in Flex 2, the compiler team was asked to address those 1.0 problems. Back then, it was a consensus among the compiler folks that it would be nice to be able to programmatically call the compiler in-process. That should solve the two main problems I described above.
My first attempt for FB2 was what I called the low-level compiler API (check out the classes in the flex2.compiler package and the main() method in mxmlc). You could pick and choose the ‘compilers’ and ‘transcoders’ and other pieces based on the hosting application’s requirements. Well, it sounds great. However, it’s too flexible - FB2, the hosting application, needs to have a lot of new codes in order to integrate with the low-level API. So after the release of FB2 and with the feedback from the FB team, I built on top of the low-level compiler API a high-level Flex compiler API (the flex2.tools.oem package) for FB2.0.1 and FB3. With this new compiler API, one can programmatically compile a Flex application with a few lines of Java codes:
Application app = new Application(new File(”helloworld.mxml”));
Configuration c = app.getDefaultConfiguration();
c.setSourcePath(…);
app.setConfiguration(c);
app.setOutput(new File(”helloworld.swf”));
app.build(true)
I can talk about how to use the Flex Compiler API here but Matt Horn’s Flex Compiler Guide (PDF) is the best IMO! Please check it out.
What I really want to talk about here is this in-process vs. out-of-process debate.
Well, I actually don’t want to debate because it is evident that FB moves from one set of (out-of-process) problems in version 1 to a new set of (in-process) problems in version 2 and 3. The most obvious one is that the compiler competes with the other features in FB3 (e.g. smart editing, profiling, design view) for CPU and memory resources.
So, is it a bad decision to move from doing out-of-process to in-process? My answer is no. Some customers have only a couple of projects in their workspace so the in-process approach works just fine. However, some of them have over 20+ so the out-of-process approach (I mean out-of-process and on another machine) provides a viable option. In other words, you need FB to give you both options.
But FB3 is out and it only supports in-process compilations and you can’t wait for the next release? Well, the good news is, FB3 uses the Flex Compiler API. So, all you need is implement a RPC version of the Flex Compiler API; add out-of-process to FB3 as a new SDK; run a server that uses the original flex-compiler-oem.jar and viola…
Since I designed and implemented the API and know the API very well, it’s pretty easy for me to implement the RPC version. In fact, I spent the last few days doing a prototype and IT WORKS! Click the thumbnail image below to see the screenshot.
I hope to polish it up and make it available as soon as possible. If you’re willing to be an early alpha tester, please shoot me an email.

This is extremely interesting to me. We have an app that crashes Flex Builder after every compile. We simply can’t allocate FB enough memory (and still run an OS) to compile and actually acheive GC before it crashes.
This would solve that problem and make a huge increase in productivity.
ML
Hi Clement Wong,
This blog is very useful to clarify developers doubts about the flex compiler, congratulations!
I am a college student and I will present a seminar about the flex compiler (actually I will talk about AS3 language and its compiler).
There are a few things that I am still looking for. So if you could send me an e-mail or even answer here I will appreciate it. Note this do not need to be a very detailed explanation, just a notion how it work.
I tried to found this on the source of compiler, but only analyzing the source it is not that easy to reach this information.
That is it:
* What strategies flex compiler does the syntactic analyzer uses? (e.g. “Recursive descent parsing” or a hybrid approach or other).
* What strategies flex compiler uses to handle the errors? (e.g. “panic mode” or a hybrid approach or other).
Thank you!
Again: congratulations for you initiative.
Thanks for the great work.
I am wondering:
How hard would it be to add a method to the interface that would allow us to add extensions to the AS compiler?
and then
How hard would it then be for us to write such an extension?
Greetz Erik
Hi,
I am talking a bit with velo at the flex-mojos project, because I am thinking about providing rpc, out-of-maven-process-compilation, to the current maven plugins, or maybe just flex-mojos. This to avoid the penalty of warming up the flex compiler each time I type “mvn” at the command-line.
To do this, I could really use the code you write about in your prototype. Would that maybe be possible?
Tech Per
Hi Michael, if you’re going to try hfcd, make sure that you bump up the -Xmx setting in jvm.config (on Windows) or hfcd (on Unix/Mac).
Hi Rodrigo, For parsing and analyzing MXML, it’s a bit more complicated than recursive decent but it’s accurate for AS3. When the compiler encounters an error, it logs the error to a Logger provided by the caller. It then keeps compiling other sources until it can’t go further or it encounters too many errors (100 is the max).
Hi Erik, It would be nice to expand the compiler API to allow users to specify transcoders, compilers and extensions. I would say that it’s not difficult for me to do ‘cos I know the compiler code quite well. But you need to run the API addition proposal by Adobe. Extensions, in my opinion, are not difficult to write - you just need to study and mimic what the other existing extensions do.
Hi Tech, yeah, I’ve just made it available in my latest postt. Please give it a try!
About my last comment about the exception: I got another version of hfcd directly from VELO, and it worked without problems.
This is really nice, but how official will this hellfire rpc compiler prototype become? Will it go open source? Will it be a product?
[...] Coding! - The Unofficial Flex Compiler Blog」より、「Hellfire Compiler」(とその設定方法)。 [...]