With the ability compile C and C++ code and leverage it via ActionScript, Adobe's project Alchemy should be on your radar. If you haven't heard of it yet, here's a direct quote from Alchemy's labs page giving a little more description:
“With Alchemy, Web application developers can now reuse hundreds of millions of lines of existing open source C and C++ client or server-side code on the Flash Platform. Alchemy brings the power of high performance C and C++ libraries to Web applications with minimal degradation on AVM2. The C/C++ code is compiled to ActionScript 3.0 as a SWF or SWC that runs on Adobe Flash Player 10 or Adobe AIR 1.5.” via Adobe Labs
So, let's jump right into the nitty-gritty and get Alchemy setup so you can start compiling some C code. I will be running through the steps for setting up Alchemy on a Windows machine, so some of this may be different depending on your platform.
Start by heading to Alchemy's download page and pick up the correct Alchemy download package for your platform. Once the download completes, unzip the archive. I unzipped my archive to C:\alchemy so that in the folder 'alchemy' are all the files that were inside the 'alchemy-cygwin-v0.5a' folder.
Now head over to Cygwin (Direct EXE Download) and pick up their command line tool so we can execute Linux like commands. Start the installation process and when you reach the package selection screen, select the following packages (do so by clicking the refresh looking icon next to each package):
- Perl (1st image)
- Archive->zip (2nd image)
- Devel->gcc-g++ (3rd image)
Once you've selected those packages, finish the installation process. The installation may take some time, depending on the download speeds you get from the mirror you choose. I would recommend against the "www.very-clever.com" mirror since the two times I used it I got 4kb download speeds! So, it took about 2 hours to download and install, which was very painful. Also, once Cygwin is installed completely, move the setup.exe and any folders it produced to the C:\cygwin folder.
While that is downloading, lets make sure you have Java installed. Go to Start->My Computer->Local Disk->Program Files, and you should see a Java folder in there. If you don't, head to the Java download page and download and install the latest "Java SE Runtime Environment". Make sure this is done before installing Cygwin, otherwise restart Cygwin after you install Java.
So, now you should have Alchemy downloaded and unzipped to your hard drive, Java downloaded and installed if it wasn't already, and Cygwin downloaded and installed with the above packages added. Next we need to get the Flex SDK if you don't have it already, which can be found here under "Adobe Flex SDK" (The first listed, the largest package): http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3. Go ahead and just grab a Milestone Release Build, unless you're feeling a little daring ;) Make sure you unzip the archive into a folder that will not be moved or deleted. I added it to my C:\ drive where both alchemy and cygwin are sitting, example: C:\FlexSDK.
Let's now add the source path to achacks, and the Flex SDK bin folder to Cygwin's path. Go to Cygwins home folder (for me C:/cygwin), then open the 'etc' folder and open up the file "profile". Open the file in real text editor, otherwise saving the file may change the file structure and you'll get errors. Find the following:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:$PATH.Change it to:
source /cygdrive/c/alchemy/alchemy-setupMake note that it should become two lines. You'll need to change the path names if they aren't the same as yours. Remember that '/cygdrive/c/' for me stands for 'C:/'. Save the file and open Cygwin. Navigate to your Alchemy folder using the cd (change directory) command. For me, the command looks like so:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/cygdrive/c/alchemy/achacks:/cygdrive/c/FlexSDK/bin:$PATH
cd C:/alchemyNow that we're in the proper directory, run the following command:
./configYou should see something similar to this, but if you see warnings or errors about adl.exe, make sure your Path is correct to the bin directory in the FlexSDK folder from the PATH above.

Now go to your Alchemy folder on your hard drive and open the alchemy_setup file. Look for this line
#export ADL=/path/to/your/adl (or adl.exe)Replace the entire line including the pound sign (#) with the following:
export ADL=/cygdrive/c/FlexSDK/bin/adlMake sure to change the path to reflect your path to the Flex SDK adl. Also, just above this line you should see:
export ASC=$(cygpath -m -s -p $ALCHEMY_HOME/bin/asc.jar)I had to change that to read:
export ASC=$ALCHEMY_HOME/bin/asc.jarNow make sure everything is saved and close Cygwin then re-open it. Change to the Alchemy/bin directory by using cd (change directory) command:
cd C:/alchemy/binRun the following command:
Now change to the Alchemy/samples/stringecho by running the following command (if you're still in the Alchemy/bin directory:
ln -s llvm-stub llvm-stub.exe
cd ../samples/stringechoThis basically says, go back one directory and look in samples for stringecho folder. If you're not in the bin directory, use the full path. Before compiling we need to turn alchemy on by running the following command:
alc-on;Now type in the following command to compile the sample:
gcc stringecho.c -O3 -Wall -swc -o stringecho.swcYou should see something similar to this

mxmlc.exe -library-path+=../stringecho.swc --target-player=10.0.0 EchoTest.asThat should have spit out an EchoTest.swf in the as3 folder. If you run the SWF in the debug player, it will trace "foo". The next article will explore Alchemy a little deeper when we create our very own first Alchemy project. Keep in mind each time you open a Cygwin terminal, before compiling with gcc you should turn "alc-on;".
Thanks for reading!