Curious about Adobe Open Source? Get started with the Flex SDK on Mac OS X
How about creating a SWF that runs in the Adobe Flash Player without building it in the Flash or Flex Builder authoring environment, using tools that are free and open source? Ever since Adobe made the move from ActionScript 2.0 to 3.0 there has been a gem of a toolkit available that allows precisely that. The Flex SDK (Software Development Kit) allows developers to create SWFs from ActionScript and MXML source code, and with the right setup is not difficult to configure and use.
Housed at Adobe Open Source, the Flex SDK is available in two incarnations through the site:
- The Open Source Flex SDK containing everything needed to create a functional application using ActionScript and/or MXML and the Flex framework.
- The Free Adobe Flex 3 SDK containing everything in the Open Source Flex SDK plus additional components such as advanced font encoders, tools for packaging Adobe AIR applications, and the Adobe Flash Player.
- Download the latest Flex SDK from Adobe Open Source. Rename the SDK folder
flex_sdk_3and place it in/Applications/on your hard drive. - Locate Apache Ant on your system. Ant will already be installed if you have installed the Mac OS X Developer Tools (which are an optional install included with every version of OS X) or are running Leopard.
Open Terminal and type:
whereis antIt should say something like
/usr/bin/ant
If Ant is not installed, no path will be shown in Terminal. To install Ant I recommend using MacPorts, an excellent open source utility for managing unix tools on Mac OS X (follow these well written directions for installation). If you are not comfortable using the Terminal, there is a GUI available for MacPorts called Porticus.
- Copy the Flex Ant tasks to your Ant installation’s library. These will allow Ant to communicate with the major Flex SDK tools. To copy the tasks, first locate the Ant
libdirectory, which will be in Ant’s main installation folder. For example on Mac OS X 10.5 it appears atusr/share/ant/lib. Copy/Applications/flex_sdk_3/ant/lib/flexTasks.jarinto this directory. -
If you are an advanced user and would like to utilize Unit Testing using FlexUnit, Download the FlexUnit Ant Tasks. Place these in the Ant installation’s library folder as well.
(Note: The project template you will download from my site in the next step includes two SWCs for use with unit testing. For those that may be curious where these came from, here are the links to the original locations: FlexUnit SWC library and FlexUnit Optional SWC library)
- Download the Flex SDK example application template from my site. Unzip the archive and place the
FlexSDKProjectTemplatefolder on your desktop. Open the folder. -
Make a copy of
build.properties.templateand rename itbuild.properties. -
Open the
build.propertiesfile you just created and edit theREQUIRED TOOL LOCATIONSsection to reflect the path to the Flex SDK, your preferred web browser, and the location of the Flash Player (which you will need to download if you have not already done so). - Using Terminal navigate to the example application template. For example:
cd Desktop/FlexSDKProjectTemplate/
And then type the following:
ant run
The sample application will launch, typing
ant usagewill show you what other options are available, such as creating documentation, SWCs, or launching the application in a web browser. -
Lastly, to enable the
trace()method so that it will work from your code when using the Flash debug player, create a textfile calledmm.cfgand fill it with the following:TraceOutPutFileName=flashlog.txt ErrorReportingEnable=1 TraceOutputFileEnable=1 MaxWarnings=0
Place this file at
. Whenever you have a
/Library/Application Support/Macromedia/mm.cfgtrace("some text");statement in your code, it will be written to:/Users/[your username]/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt
How to use the Flex SDK
I have developed an Apache Ant build script that makes—after some configuration—the Flex SDK quite easy to use on Mac OS X. Here’s how to configure it:
Please leave comments with any suggestions, problems, questions, etc. Enjoy!
Troubleshooting
Problem: Running ASDoc produces: Execute failed: java.io.IOException: /Applications/flex_sdk_3/bin/asdoc: cannot execute
Solution: This mostly likely means the ASDoc script Ant uses is not set to be executable. Type the following in Terminal:
cd /Applications/flex_sdk_3/bin/ chmod +x asdoc
The first line changes the directory to the one ASDoc resides in. The second line makes ASDoc executable.
Problem: Running ASDoc produces: exec returned: 255
Solution: This mostly likely means the ASDoc script (which is just a text file) contains Window-style line endings. These will need to be converted to linux.
Install dos2unix using MacPorts and type the following in Terminal:
cd /Applications/flex_sdk_3/bin/ dos2unix asdoc
This will turn off the executable bit in the permission tables, so you will have to re-enable that using the instructions in the first solution above.
Problem: Running ASDoc produces: Could not create toplevel.xml: /Applications/flex_sdk_3/asdoc/templates/asDocHelper: cannot execute
Solution: This mostly likely means that a helper script used by ASDoc is not set to be executable. Type the following in Terminal:
cd /Applications/flex_sdk_3/asdoc/templates/ chmod +x asDocHelper

January 6th, 2009 at 7:42 am
Thanks for the great write up! I thought I would add that for Linux users the process is very similar. However, for once, Linux users actually have the royal treatment! Adobe has been working on Flex Builder for Linux for some time now and there is a alpha version for download at Adobe Labs (http://labs.adobe.com/technologies/flex/flexbuilder_linux/). I’ve been using this for over a year. Sometimes the alpha expires and you have to update to a new version, but the last time I updated it said it didn’t expire for another year! This seems to be a long-term project for Adobe.
This isn’t quite like Flex Builder for Mac and Windows. It’s strictly a plugin and there is no ‘design’ mode. But the code tools are excellent and provide you with true code hinting & completion for AS3 & MXML. This is the easiest way to get rolling with Flex development, and if you’re on Linux you can do it for free! (for now anyways).
March 16th, 2009 at 1:07 pm
your tip about setting the executable flag for asDocHelper was exactly what I needed! thanks for posting this info.
September 18th, 2009 at 2:55 pm
I do have ant installed and running whereis and produces:
/usr/bin/ant
However, I can’t find this directory anywhere on my system. Is it only available through the terminal?
September 19th, 2009 at 12:38 am
It’s a hidden directory, so from the Finder you have to go to Go -> Go to Folder… and type /usr/bin then it will show up.
November 4th, 2009 at 8:38 am
Hi anselm,
Your tutorial is very good and so far the easiest solution to compile .. I think.
But I’m struggeling with this code out of a batch file. Is it possible to adapt the code to use \ant\?
If I adapt your build.properties I got this message:
Target \run\ does not exist in the project \null\.
Where to fill in for example the local things…
@echo off
-locale=en_US -source-path=locale/{locale} -include-resource-bundles=CairngormMessages,Errors,FinishScreen,ImportBrowser,ImportModuleLoader,IntroScreen, MediaTypes,PendingMessages,SearchAuthenticationScreen,SearchImportView,Tagging,TermsOfUseScreen, UploadImportView,WebcamView,collections,containers,controls,core,effects,logging,messaging,rpc,skins, states,styles,SharedResources,PendingMessages -output=en_US_ContributionWizard.swf
November 4th, 2009 at 9:18 am
Not entirely sure I understand the question? You want to add extra parameters to the compiler? You can do this by adding these in the build.xml file in the compile target. Find where there are already parameters for mxmlc. It looks like this:
actionscript-file-encoding = "UTF-8"
keep-generated-actionscript = "true"
incremental = "true"
strict = "true"
default-background-color = "0x${background.color}"
default-frame-rate = "${framerate}"
>
You can add additional arguments to this each on a new line under “default-frame-rate = …”
November 4th, 2009 at 10:38 am
Sorry.. I want “only” compile locale recources. Is it possible to put the “locale” information to your code?
November 4th, 2009 at 10:51 am
Hi Rob,
Yeah, I think it would be in build.xml as mentioned above, like:
…
default-background-color = “0x${background.color}”
default-frame-rate = “${framerate}”
locale = “en_US”
source-path = “locale/{locale}”
…
etc.
See how that’s formatted from what you posted?
November 4th, 2009 at 11:02 am
I will try it.. your script is the only one, which throw no error like this:
BUILD FAILED
Target \run\ does not exist in the project …
http://www.nbilyk.com/flex-localization-example
http://cookbooks.adobe.com/post_Easily_compile_resource_bundles_using_Ant-12765.html
November 5th, 2009 at 11:33 pm
It looks like that second link you posted has instructions for creating the build target. Have you run through this? If you get it working I would love to post your additions.