[UPDATED Jan 3, 2006: Added "flCompile and httpTest", updated workflows to make it easier to customize command line parameters like swf dimension and background color]

There are a lot of things I want to play with in AS 3 and Flex 2, but there's one problem: I'm using Mac OS X, and FlexBuilder 2 is only available for Windows right now. Fortunately, I stumbled upon this page via this blog entry by Robin Hilliard, which explains how to compile ActionScript 3 and Flex 2 on the Macintosh using the command line.

I'm a Mac user though! Commandlines are for lesser OSes! Refusing to stoop to typing arcane commands into the Terminal, I instead spent my evening learning to use Automator and the rather eccentric AppleScript language to build a solution. The result is a contextual menu plugin that will compile AS3 and Flex 2 MXML files, then open them in Safari for testing. It's still a little rough around the edges, and it's nowhere near as nice as working in FlexBuilder2, but it works! I also fleshed out the instructions for getting command line compiling working on the Mac.

You can download it by clicking here (10kb). It requires Mac OS X 10.4. Please read the ReadMe file - the contents of which follows:

Disclaimer
I take absolutely no responsibility for any problems you experience or damages (direct or indirect, including but not limited to loss of data) caused by using these workflows. I have tried my best to make sure they are totally safe, but I am not an AppleScript expert or a command line guru. Use at your own risk.

About
The flCompile context menu workflows allow you to compile and test AS3 and Flex2 MXML files in Mac OSX Tiger (10.4) without having to use the command line directly.

Once you have installed these workflows (see below), you can simply select an AS3 or MXML file in the finder then right click (or control click) it and select one of the flCompile workflows from the "Automator" submenu. The command will launch the terminal and execute a command to begin compiling the file. If you selected the "flCompile and Test" command, it will open a prompt asking you if you'd like to launch the compiled SWF - you MUST wait until the compile is done in the Terminal before clicking OK!


Installation
First, you must set things up so that you can compile AS3 and Flex2 MXML files on OSX. Macromedia doesn't offer any official support for doing this, so it is a little involved:
1) Using a PC or VirtualPC (I used the latter), download and install the Flex 2 Alpha (full install) from labs.macromedia.com

2) Open the directory it was installed in (usually C:\Program Files\Macromedia\Flex Builder 2 Alpha 1), and copy the "Flex Framework 2 Alpha 1" directory to your MacOSX 10.4 computer. You'll probably also want to copy the "Install Flash Player 8.5 OSX.dmg" file from the "Player/Version 8.5 alpha 1/Debug" directory in the install directory.

3) Rename the "Flex Framework 2 Alpha 1" directory on your Mac to "flex", and move it to your home directory (your user directory ex. Users/Grant/). This should allow you to compile AS3 and Flex2 MXML files via the command line. Install the 8.5 player using the dmg file.

4) Verify that everything is working by copying the "HelloAS3.as" included with flCompile to your home directory, and executing the following command in the Terminal:
java -jar flex/lib/mxmlc.jar -flexlib flex/frameworks -file-specs helloas3.as
It should give you compiling messages, and generate a "HelloAS3.swf" file in your Home directory.

Once that's working, you just need to install the flCompile workflow files:
1) Move the "flCompile.workflow" and "flCompile and Test.workflow" files into your "Library/Workflows/Applications/Finder" directory. You may have to create the "Workflows/Applications/Finder" directories if they do not exist.

2) Make sure it is working by clicking on an AS3 or Flex2 MXML file in the finder, then right clicking (or control clicking) on it and selecting "flCompile" from the Automator submenu.


Using flCompile and httpTest
flCompile and httpTest was added on January 3 in response to a problem in the Mac 8.5 player preventing loads from working properly locally. The only solution I found was to test content on a web server, which can be a pain if you have to upload via FTP every time. Instead, you can turn on "Personal Web Sharing" in the "Sharing" control panel, and use the web server built into OSX to test.

The httpTest command lets you develop in a subdirectory ("as3/" by default) of your "~user/Sites/" directory and compile and test using the localhost address. To change the subdirectory, see the Customizing flCompile section below.

For more information, view this entry on the gBlog:
http://www.gskinner.com/blog/archives/2006/01/local_loading_i.html


Customizing flCompile
You can easily customize the command line params used by flCompile (or the other workflows) by double clicking on the workflow file to open it in Automator. At the top of the second workflow item (Run AppleScript) you will find a cmdLineParams variable declaration that you can update to suite your needs.

Likewise, near the top of the third worflow item of the "flCompile and httpTest" file you will find a serverPath variable declaration that you can change to whatever subdirectory path you would like to use when testing SWFs in the local webserver.


Limitations / Bugs
I've never really worked with AppleScript before, so these workflows have a few limitations at the moment. I hope to fix these by converting to pure AppleScript (rather than Automator and AppleScript) over the next couple weeks.

- I haven't determined how to get a reference to the file that was right clicked on in Automator yet - this means that you MUST select the file (so that it is highlighted) and then right click it and choose a command.

- I haven't found a way to halt execution of the workflow if an inappropriate file extension is found, so you'll just get an AppleScript error, and a friendly message in the Terminal if something other than a ".as" or ".mxml" file is selected.

- I haven't found a way to determine for sure when the compile is done, so Compile and Test relies on the user clicking ok when the compile is complete to indicate when the SWF should be opened.

- always opens a new Terminal window. I'd like to make it open in the topmost Terminal window

If you are an AppleScript guru and want to lend a hand, I would definitely welcome it.


Credit and thanks:
I'd like to thank and credit whoever put together this page (Alisdair Mills?) for the info on how to compile on OSX:
http://www.mook.co.uk/~alisdair.mills/mxmlc_compiler_osx.html

I'd also like to thank these sites for the great AppleScript information:
http://www.macosxhints.com/
http://bbs.applescript.net/