Today I’ve started writing some ActionScript, and I’ve been attempting to make sense of the best way moving forward to write and build AS using my new text editor, Sublime. I thought this might be helpful for other people who may want to do something similar.
So first off, this article will get you compiling using mxmlc in Sublime.
But this is slow. GLACIALLY slow. Additionally it needs a line_regex (which I’ve added in the comments) so that you can press F4 and be taken to the error. The best way moving forward is to use something that supports the compiler’s ‘incremental compilation’ feature, and pipe that output to sublime.
So what is incremental compilation? Essentially this is a configuration of the compiler where the compiled objects are kept in memory, and the compiler only re-compiles items that have been modified. Adobe has kindly provided us with a command line utility called Flex Compiler Shell (fcsh) which you can use in a terminal. But this is an interactive utility, and doesn’t really play happily with much of anything, except a human being typing stuff in it. Or…screen.
Enter ‘fcshctl‘, a couple command line scripts that ‘maintain’ a running fcsh instance in a screen session. When you first use fcshctl, it will create an fcsh session inside a screen session. When you issue commands to it, it will attach a logfile to the screen, execute the command, and upon completion of execution, output the logfile to stdout.
The upshot of this is that you can do your compile in Sublime using fcshctl, which is significantly faster, and then Sublime gets the compiler output which it can then regex and parse into errors which can be navigated via F4 or double-click. Please note: due to the limitations of Sublime’s build system, I still do a lot of things outside of Sublime in my workflow. These could most likely be added to some kind of python-based system in the future.
Prerequisites:
- A bit of unix command line comfortability.
- This zip file. It includes a functional fcshctl, an example swf build config, and the sublime-build file.
- The Flex SDK.
- This works on OS X. I’d imagine it should work on Linux. Definitely not Windows. But they have FlashDevelop.
Installation:
- Download the above files.
- Unzip the Flex SDK somewhere. I keep my copies in ~/Library and symlink the latest version to ~/Library/Flex4.
- Next put the fcshctl script somewhere. I put mine in ~/bin. Set your FLEX_HOME var inside the file, example:
|
1 |
PATH_TO_FCSH="/Users/chris/bin/fcsh" |
- Finally put the sublime-build script in your Sublime Users folder. You’ll need to hardcode the location of fcshctl in this file like so:
|
1 |
"cmd": ["/Users/chris/bin/fcshctl","compile 1"], |
Usage:
I’ll usually create a simple shell script for initializing the build. An example is included in the zip.
|
1 2 3 4 5 6 7 8 9 |
#!/bin/bash
# Salt to taste.
BASEDIR=/Users/chris/Projects/fcsh-sublime/example
#Shut down fcshctl between calls to this script.
fcshctl quit
#This also assumes that fcshctl-mxmlc is accessible on the path.
fcshctl-mxmlc --load-config+=$BASEDIR/conf/game-flex-config.xml -o $BASEDIR/site/swf/CompileExample.swf $BASEDIR/src/CompileExample.as |
Execute this on the command line to initialize the code:
|
1 |
Awesome-Sauce:bin chris$ ./buildGame |
After executing, if things went ok, you’ll see the output saying you’ve built a swf:
|
1 |
/Users/chris/Projects/fcsh-sublime/example/site/swf/CompileExample.swf (758 bytes) |
After this, you can press F7 in sublime to build. It should happen quite quickly. And that’s all there really is to it.
Caveats
This is not a replacement for a real build system. You should most likely be using Ant and Hudson. The only reason I use this is to quickly execute builds, and those seconds add up. But having a build system that will execute an Ant build upon commit should be the method used to create your final deliverable.
Multiple builds at the same time wil require additional sublime builds that run compile 2 etc. I’ve found that frequently I’m only building one item, so this limitation is not an issue for me.
Conclusion
If you’re wanting to do some serious ActionScript development you’re going to want to speed up compilation and provide Sublime with access to its output. While the method detailed here is kind of complicated, it works well, and I have yet to find a better solution to AS3 dev in Sublime. Hopefully this will help others who enjoy working in Sublime to work faster and smarter!


















