There have been a lot of posts recently about how to compile
Flex applications and ActionScript projects from the command line (on
Windows, Mac, and Linux). Mike Chambers has a
nice summary which points to all the information you need to
get going, and has a
bash script which wraps the mxmlc compiler to make
I have some specific compilation needs, however, so I decided
to write a
Ruby script to wrap the mxml compiler (I’m not a huge fan of
bash once my scripts reach a certain level of complexity). Once you
Flex environment set up, just download
the script, make sure it’s in
your path, configure it, and you can compile like this:
% mxmlc.rb MyApplication.mxml
The script has the following flags:
Help. Prints out this help message.
- -t Tail. After compilation,
tails the file specified by the
TAIL_PATH variable. (Useful for debugging your application.)
- -o Open. After compilation,
opens the generated swf in the
application specified by the OPEN_APP variable. (This should probably
be something like ‘firefox’ or ‘safari’.)
- -s Show. Show the compilation
command rather than actually
running it. Useful for debugging if it’s not working like you expect it
- -c Clean. Removes cache files
before compilation so you
compile the project completely from scratch.
Before running the script, you have to configure it by
defining the following variables at the top:
- FLEX_PATH: The path to your
Flex library installation.
- AS_LIB_PATH: Path to your
ActionScript libraries. In other
words, your classpath. You can specify multiple directories by
separating them with a ‘:’ character. You can also add a ‘$’ character
anywhere in any of the paths which essentially acts like a wildcard.
For instance, if I added the directory
/Users/cantrell/projects/$/src/actionscript, then the script would
iterate through all the directories in /Users/cantrell/projects and add
all those directories, plus /src/actionscript to the classpath. It’s an
easy way to include an entire source tree with one path. (If the
generated directory doesn’t actually exist, the script automatically
- TAIL_PATH: The path to the
file you want to tail if you
pass in the -t flag.
- OPEN_APP: The application you
want to open the resulting
swf file in if you pass in the -o flag.
Let me know if you have any problems getting it to run. It was
written and tested under Ruby version 1.8.2 which should already be
installed on your Mac. To get the alpha version of the Flex Framework
and the compiler, check out Flex
Builder 2 on Adobe Labs.