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/" MyApp.as
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/ MyApp.as
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):
<actionscript-classpath>
<path-element</Users/mesh/src/flashplatform/projects/corelib/trunk/src/actionscript3/</path-element>
<path-element</Users/mesh/src/flashplatform/projects/testlib/trunk/src/actionscript3/</path-element>
</actionscript-classpath>
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/" MyApp.as
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/bash
flex='/Users/mesh/bin/flex/'
classpath=''
if [ -n "$ASCLASSPATH" ]; then
classpath="-actionscript-classpath `echo $ASCLASSPATH | sed 's/:/ /g'`"
fi
echo $classpath
java -jar "$flex/lib/mxmlc.jar" -flexlib "$flex/frameworks/" $classpath --incremental=true $@
Make sure to change the:
flex='/Users/mesh/bin/flex/'
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:
mxmlc MyApp.as
The script is written so that you can also pass any supported mxmlc command line arguments to it, like so:
mxmlc -verbose MyApp.as
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:
- Compiling and Developing with ActionScript 3 and Flex 2 on the Mac (labs)
- Using the mxmlc command line compiler to compiler ActionScript 3 and Flex 2 Framework applications (labs)
- Compile AS3 on Mac (Josh Buhler)
Hope that help makes compiling on Mac and Linux easier. If you have any comments / suggestions / corrections, please post them in the comments.







Awesome post!
When Christmas winds down, I am going to give this a go!
ericd
22 Dec 05 at 9:19 am
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!
Josh
22 Dec 05 at 9:35 am
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 chambers
mchamber@adobe.com
mike chambers
22 Dec 05 at 9:46 am
I’ve got a list of them at home I’ll fire off to you later.
Josh
22 Dec 05 at 9:56 am
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.
Anona
22 Dec 05 at 2:20 pm
Hello Mike,
Last time i tried to see 3d engines made in AS3 it was not working.
you can check it at:
http://blog.andre-michelle.com/
There 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.
Bazard
22 Dec 05 at 8:55 pm
>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.
fyi, we fully support ColdFusion on Mac:
http://www.macromedia.com/devnet/logged_in/dcooper_merrimack.html
We 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 chambers
mchamber@macromedia.com
mike chambers
22 Dec 05 at 10:35 pm
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 appreciated
Thanks
George Medve
23 Dec 05 at 6:12 am
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
jaco
24 Dec 05 at 2:11 am
>that’s sound great to me in linux, unfortunately there are both player 8 & 8.5 not available for that platform
Yes. You can find info on Flash Player on Linux here:
http://www.kaourantin.net/2005/12/flash-player-8-for-linux-update.html
Compiling on Linux can still be useful though, for example if you need to setup an automatic build system.
mike chambers
mchamber@adobe.com
mike chambers
24 Dec 05 at 10:14 am
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 http://www.winehq.org.
It 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
jaco
25 Dec 05 at 9:13 am
– “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.
BH
26 Dec 05 at 11:46 am
> 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.
- MD
Mike Downey | Product Manager, Flash | Adobe Systems
Mike Downey
28 Dec 05 at 1:07 am
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!
ianc
28 Dec 05 at 3:21 pm
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.
cesperanca
10 Jan 06 at 9:45 am
i get “command line: unknown configuration variable flexlib”
can anyone help?
ej
9 Mar 06 at 6:06 pm
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…
Bill Garr
20 Jun 06 at 1:32 am
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
rakri
17 Oct 06 at 5:10 am
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.mxml
defaults: Error: unable to open ‘/opt/fds2/flex_2_sdk/frameworks/flex-config.xml’
I am sure the paths are correct…why this error??
suyash
5 Feb 07 at 7:25 am
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.bin
root@localhost bin]# java -version
java 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.mxml
Loading 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.mxml
Loading configuration file /opt/fds2/flex_sdk_2/frameworks/flex-config.xml
Segmentation fault
suyash
9 Feb 07 at 9:18 pm
suyash,
You are still using GCJ. There are pretty good instructions here: http://ccl.net/cca/software/SOURCES/JAVA/JSDK-1.5/index.shtml but basically, you just need to install ftp://jpackage.hmdc.harvard.edu/JPackage/1.7/generic/RPMS.non-free/java-1.4.2-sun-compat-1.4.2.13-1jpp.i586.rpm in addition to the Java package you already installed, then run: alternatives –config java
Sean
6 Mar 07 at 10:50 am
Hi,
I’m using Ubuntu OS and new to flex3 and AS3.
I had written a sample file (Test.as) using AS3 which displays a button. Same way written it using mxml also and named it as Test.mxml
By giving “mxmlc Test.as”.I’m able to compile Test.as successfully,
But If I compile by giving “mxmlc Test.mxml”. Its showing me “Segementation fault (core dumped)”
Any suggestions on how to get rid of this.
Thanks,
Anil
Anil
5 Mar 08 at 10:02 pm
Hey guys,
So i’ve been doing some flex 4 flashplayer 10 work and felt like switching over to my Mac for a bit.. here is what it did..
download flashplayer 10 do an uninstall .. install.
download the flex 4 open source.. extract..
add this to your frameworks/flex-config.xml file
within the tag
macFonts.ser
hit up terminal..
go to your mxmlc.jar directory
> cd PathToFLEX4/lib
then type
> java -jar “mxmlc.jar” PathToActionScript/Code.as -load-config PathToFLEX4/frameworks/flex-config.xml
bingo bango..
if you want to get fancy..
add this to your flex-config.xml
for a little bit cleaner execution line..
PathToActionScript/
good luck!
Daver K
22 Sep 08 at 12:20 am