Update: - These instructions don’t work 100% with the files from Flex 2 Beta 2, or the recently released Flex SDK. I’ve posted some new instructions here: http://www.joshbuhler.com/2006/04/17/using-the-flex-sdk-with-xcode/
Yesterday I mentioned a site that had instructions on how to compile ActionScript 3.0 files on your Mac using the command line compiler.
That’s all well and good, but once you get going on a project, it can get a little tiring typing out the commands to compile your swf each time. However, if you’ve been using Xcode for your ActionScript work, you can set it up to compile your AS3.
For these instructions to work, I’m assuming that you have the Apple Developer Tools installed, which you can get for free from developer.apple.com
Step 1 - Installing Files
First, you’ll need to download the Flex 2 Alpha files from labs.macromedia.com to a Windows machine. Once you install them, follow the instructions from yesterday:
Transfer the install directory (”Flex Framework 2 Alpha”) to your mac. Create a new folder on your mac called “flex” and transfer the “lib” and “frameworks” folders from “Flex Framework 2 Alpha” into this folder.
However, as a variation on this, I’d suggest putting the new “flex” folder into “Macintosh HD > Developer > SDKs”, so that you have them in one location you can access for all of your new AS3 projects.
Step 2 - Creating a new ActionScript 3.0 project
Open Xcode, and create a new empty project:

Now, in the Xcode Project Window, select your new project file, and then select the “Info” button. Under the “General” tab of Project Info window, select the “Other” option for the “Cross-Develop Using Target SDK”, and browse to the folder where you copied the Flex Libraries. In my case, “/Developer/SDKs/flex”. This tells Xcode where you want to look for the Flex compiler libraries.

Next, we need to create a new build target for Xcode, or, tell it what compiler we want to use. In the Project Window, right-click on “Targets”, and add a “New Target”.

From the New Target Assistant, select “External Target” from the Special Targets category, and click the Next button.

Name the target “mxmlc”, or something that will help you remember what it is.
Now that the new target is created, we need to tell it where to find the compiler. Double-click on the new target you just created, and the Target Info should open. Under “Custom Build Command”, change your Build Tool to be /usr/bin/java.
Then, the arguments you pass will be: -jar $(SDKROOT)/lib/mxmlc.jar -flexlib $(SDKROOT)/frameworks -verbose=true -file-specs $(PROJECT_NAME).as

$(SDKROOT) refers to the path to the Flex libraries from a few steps ago, and $(PROJECT_NAME) is the name of your project file, with “.as” appended to the end. Close this window, and we should be ready to go.
Step 3 - Writing some AS3 and Compiling
Now, you’ll need to create your main ActionScript file. Make sure that it has the same name as your project. Save it, and click the “Build Button”. The build window should appear, with messages from the compiler tracing out. When the build succeeds, you’ll have a swf file in the same location as your .as files.

Of course, there are several options that you can pass to the compiler, and here we’re only passing the bare essentials. But the nice thing about doing it this way, is that for each project, you can specify what arguments you’d like to pass, and then they’ll be saved with your project to save you time in typing.
I’m sure that there could be better ways of doing this, however, it is a start, and as I keep working on it, I’ll post if I find a better way of getting this to work. Of course, if you come up with a better method, let me know.
Update: I had a chance to play around the new beta files this weekend, and some things have changed. With the new Beta files, you’ll want to take a look at the info here:
http://www.joshbuhler.com/2006/02/06/my-conversion-to-flex-and-how-to-use-xcode-with-flex-2/
Comments feed (RSS 2.0) You can skip to the end and leave a response. Pinging is currently not allowed.
Leave a Reply