Compiling ActionScript 3 and MXML on Mac and Linux

I finally switched back to Mac from Windows yesterday. I had moved to Windows a couple of months ago so that I could use the Flex Builder 2 alpha. However, after my 4th system failure in the past 3 months, I decided it was time to go back to Mac.

One of the first things I wanted to set up was my development environment so that I could continue to develop in Flex 2 and ActionScript 3. We do not currently have a Mac version of Flex Builder, but fortunately, the command line compiler (mxmlc) included with Flex builder is written in Java, which means it should (and does) run on Mac and Linux.

NOTE, currently, mxmlc is supported on windows only. The instructions below work well, but running mxmlc on non-Windows system is currently not supported.The MXMLC compiler that is included with Flex Builder comes with a Windows executable wrapper (mxmlc.exe) that makes it very easy to use on Windows. However, you can not use the wrapper on Mac or Linux. Getting the compiler to run is not too difficult once you figure it out, although it can require constructing a pretty extensive command to run. In order to make this easier, I wrote my own simple bash script that acts as a wrapper for mxmlc and makes it easy to compile ActionScript 2 and Flex 2 applications from the command line on Mac and Linux.First, you need to download the compiler and set it up on your system. We have a page on the Labs wiki that describes how to do this on non-Windows systems.Once the compiler is setup, calling MXMLC is not too difficult. Here is a typical command line to compile a simple application:

java -jar "/Users/mesh/bin/flex/lib/mxmlc.jar" -flexlib "/Users/mesh/bin/flex/frameworks/"

That would work as long as the application only used Flash Player APIs, and not external ActionScript libraries. If it used external ActionScript classes, then you would need to specify the ActionScript classpaths like so:

java -jar "/Users/mesh/bin/flex/lib/mxmlc.jar" -flexlib "/Users/mesh/bin/flex/frameworks/" -actionscript-classpath /Users/mesh/src/flashplatform/projects/corelib/trunk/src/actionscript3/ /Users/mesh/src/flashplatform/projects/testlib/trunk/src/actionscript3/

This specifies two paths to search for classes. As you can see, it begins to get a little more tedious to construct the command line. However, the Flex engineers considered this, and created a config file that the mxmlc compiler uses. You can find this setting in the frameworks/flex-config.xml file.If we add the following to the file (just un-comment the entry already in the file):


then MXMLC will know where to look for ActionScript classes, and we will no longer need to specify them on the command line.But, that still brings us back to:

java -jar "/Users/mesh/bin/flex/lib/mxmlc.jar" -flexlib "/Users/mesh/bin/flex/frameworks/"

which is still a little tedious to type each time you want to compile the application.So, I wrote a simple bash script that wraps mxmlc.First, create a new text file on your machine (I called it mxmlc), and add the following script to it:

#!/bin/bashflex='/Users/mesh/bin/flex/'classpath=''if [ -n "$ASCLASSPATH" ]; thenclasspath="-actionscript-classpath `echo $ASCLASSPATH | sed 's/:/ /g'`"fiecho $classpathjava -jar "$flex/lib/mxmlc.jar" -flexlib "$flex/frameworks/" $classpath --incremental=true $@

Make sure to change the:


to point to the folder that contains your flex files (that you installed according to the instructions here). Not that the script adds the –incrental=true flag. This enables incremental compilation and should dramatically increases compilation performance.Next, from the command line you need to make sure that the script is executable, so run this command on it:

chmod 755 mxmlc

Once you have done that, you can now compile your applications like so:


The script is written so that you can also pass any supported mxmlc command line arguments to it, like so:

mxmlc -verbose

It also supports a system level ActionScript classpath. If you want to specify your ActionScript classpath in the system, and not in the flex-config.xml file (similar to a Java classpath), just specify an $ASCLASSPATH environment variable, that contains a colon “:” separated lists of ActionScript classpath.For example, my .profile file in my home directory contains this line:

ASCLASSPATH=/Users/mesh/src/flashplatform/projects/corelib/trunk/src/actionscript3/:/Users/mesh/src/flashplatform/projects/testlib/trunk/src/actionscript3/export ASCLASSPATH

Now, any application or script on my system can access my ActionScript classpath. If this is set, then the mxmlc script will use it when compiling the application. Of course, you can continue to specify it on the command line or via the flex-config.xml file.Here are some additional resources on using mxmlc:

Hope that help makes compiling on Mac and Linux easier. If you have any comments / suggestions / corrections, please post them in the comments.

21 Responses to Compiling ActionScript 3 and MXML on Mac and Linux

  1. ericd says:

    Awesome post!When Christmas winds down, I am going to give this a go!

  2. Josh says:

    So, now that you’re back on the Mac, any idea when we’ll see new versions of the 8.5 Player for Mac that work with most the examples I’ve seen online?I’ve seen lots of cool stuff in AS 3.0 that works great on my Windows machine, but doesn’t work at all on the Mac version.Thanks for the extra info though!

  3. mike chambers says:

    Josh,Do you have any URLs of content that works on windows but not Mac? I want to make sure that the player teams know about them (since it sounds like a bug).(you can email them directly to me).thanks…mike

  4. Josh says:

    I’ve got a list of them at home I’ll fire off to you later.

  5. Anona says:

    I’d like to caution developers out there NOT to use tools like Flex and ColdFusion on a Mac where the vendor does NOT fully support them. Let’s stop pretending. If Adobe wants us to use them, let them properly support them. Until then don’t waste your time.

  6. Bazard says:

    Hello Mike,Last time i tried to see 3d engines made in AS3 it was not can check it at: were also other examples like image transformation, but i don’t remember the urls.I used Virtual PC and the windows flash player 8.5 to make it work.If we can have a new version of the mac plugin, it would be great.Thanks.

  7. mike chambers says:

    >I’d like to caution developers out there NOT to use tools like Flex and ColdFusion on a Mac where the vendor does NOT fully support, we fully support ColdFusion on Mac: have also said that we are working on a Mac version of Flex Builder 2.Regardless, if you would like to put off learning ActionScript 3 and Flex to until Flex Builder 2 is out, then that is, of course your choice.mike

  8. George Medve says:

    Any idea when we might see a version of Flex builder for OS X?Is the Flash 9 Alpha with AS3.0 support going to be available for OS X when released?Any more information re: OS X would be very much appreciatedThanks

  9. jaco says:

    hi 2 all,that’s sound great to me in linux, unfortunately there are both player 8 & 8.5 not available for that platform (ergo: no view/preview).Hope they will be soon available (player 8 at least), we know there are various issues to resolve.Merry Xmas:)Jaco

  10. mike chambers says:

    >that’s sound great to me in linux, unfortunately there are both player 8 & 8.5 not available for that platformYes. You can find info on Flash Player on Linux here: on Linux can still be useful though, for example if you need to setup an automatic build system.mike

  11. jaco says:

    thanx for the reply.I was instead thinking about a whole single/team development flow.I knew that blogs, even they are good news they contain info but yet not stuff, sorry.Hoping Adobe/MM will soon release tux flash player (and obviously flex2 for linux), if you need some kind of preview you may consider to use wine allows to run e.g. firefox 1.0.7 for ms and then flash player. I Don’t yet know if player 8.5 runs.:)Jaco

  12. BH says:

    — “If Adobe wants us to use them, let them properly support them. Until then don’t waste your time.”You obviously don’t know what you are talking about. Who cares what Adobe wants? Macromedia would want it that way.Go use photoshop and leave flash to people with a vision and an imagination.

  13. Mike Downey says:

    > Is the Flash 9 Alpha with AS3.0 support going to be available for OS X when released?We are planning to make the Blaze AS3 alpha preview available for both Mac and Win around the same time that Flash Player 8.5 is released which is currently slated for the Spring 2006 timeframe.- MDMike Downey | Product Manager, Flash | Adobe Systems

  14. ianc says:

    Actionscript is getting increasingly powerful. When ECMAScript 4 is standardised and Actionscript conforms to it will Actionscript be able to “eat its own dogfood” and compile mxml.I hope Actionscript/Javascript2/EcmaScript4 replaces Java on the client entirely both for end users and developers. And eventually on the server as well!

  15. cesperanca says:

    I had already compile some actionscript 3 classes with the eclipse plugin of flex builder 2 in linux. I can’t try the generated swf’s files in linux (because there is no flash player 8.5 for linux – for now), but when I tested them on Windows they work very well. I hope that on next version of flex builder 2 this “compatibility” be kept.

  16. ej says:

    i get “command line: unknown configuration variable flexlib”can anyone help?

  17. Bill Garr says:

    I’m having trouble compiling an AS3 project in XCode. I’ve uncommented the in flex-config.xml, tried to set a new , tried adding -sp with my path to the command line, but … nothing. It’s not finding the flash packages. Any ideas would be greatly appreciated.BTW, compiling mxml seems to work fine.Also BTW, thanks so much for posting these instrux. Still hoping to join the fun…

  18. rakri says:

    Hi Mike ,If I’ve good understood , I can develop my application on windows , after I can compile it on linux ; but , I must use flex 1.5 for it because flash player on linux is yet on version 7 .Is like this Mike ? Thank yoi for your answer .rakri

  19. suyash says:

    Hi…[root@localhost bin]# java -jar /opt/fds2/flex_sdk_2/lib/mxmlc.jar +flexlib /opt/fds2/flex_2_sdk/frameworks /opt/fds2/flex_sdk_2/bin/sample1.mxmldefaults: Error: unable to open ‘/opt/fds2/flex_2_sdk/frameworks/flex-config.xml’I am sure the paths are correct…why this error??

  20. suyash says:

    I had got JAVA segmentation fault error while compiling with mxml of default java package in FC6.I was suggested that fc6 java is buggy.So i downloaded and installed SUN’s j2sdk-1_4_2_13-linux-i586.binroot@localhost bin]# java -versionjava version “1.4.2”gij (GNU libgcj) version 4.1.1 20061011 (Red Hat 4.1.1-30)Copyright (C) 2006 Free Software Foundation, Inc.But still the SEGMENTATION FAULT error in compiling FLEX exists….Please ….Any suggestions??[root@localhost bin]# ./mxmlc –strict=true –file-specs /root/Myfirst.mxmlLoading configuration file /opt/fds2/flex_sdk_2/frameworks/flex-config.xml./mxmlc: line 34: 2736 Segmentation fault java $VMARGS -jar $FLEX_HOME/lib/mxmlc.jar $*[root@localhost bin]# java -jar /opt/fds2/flex_sdk_2/lib/mxmlc.jar +flexlib /opt/fds2/flex_sdk_2/frameworks/ /root/Myfirst.mxmlLoading configuration file /opt/fds2/flex_sdk_2/frameworks/flex-config.xmlSegmentation fault

  21. Sean says:

    suyash,You are still using GCJ. There are pretty good instructions here: but basically, you just need to install in addition to the Java package you already installed, then run: alternatives –config java