Today’s experiment: using Adobe Flex on Ubuntu.
Now, you can get some Adobe tools on Ubuntu. As I understand it, there are three sets of tools:
- The Flash IDE
- This is what people think of when they think of how to create Flash stuff. It’s not available for Ubuntu.
- Flash Builder
- The Flex SDK
- The Flex SDK is the command line compiler for Flex. It’s available for Ubuntu. The latest version is v4, but Flex 4 doesn’t seem to work on Ubuntu. Flex 3 works perfectly, though, hooray, and Flex is open source (well, there are two flavours: the “Adobe SDK” and the “open source” SDK. I prefer using open source when possible, and it works fine; I don’t know what’s extra in the non-open-source one, but we don’t need it anyway.)
Installing Adobe Flex
So, first step: make a folder, download the Flex 3 SDK, and unpack it:
$ cd ~ $ mkdir flex $ cd flex $ wget http://fpdownload.adobe.com/pub/flex/sdk/builds/flex3/flex_sdk_22.214.171.12484_mpl.zip $ mkdir flex_3_opensource $ unzip -d flex_3_opensource flex_sdk_126.96.36.19984_mpl.zip
There’s a small, weird problem with Flex 3: the executable scripts are in DOS format, which Ubuntu doesn’t like, and they’re not executable. (This is fixed in Flex 4, but as noted Flex 4 doesn’t work.) So, let’s convert them:
$ sudo apt-get install dos2unix $ chmod +x flex_3_opensource/bin/mxmlc $ dos2unix flex_3_opensource/bin/mxmlc
We also need Sun’s Java - the Flex SDK is written in Java - and it needs to be set as the default Java.*
$ sudo apt-get install sun-java6-jdk $ sudo update-alternatives --config java
…and in the list of possible Javas, choose
(We can now test that it works: run
it should say something about “a target file must be specified”, which
means that it’s working.)
Getting Flixel and a game
Next step is to get the Flixel source.
$ wget --no-check-certificate -O flixel2.zip http://github.com/AdamAtomic/flixel/zipball/master $ unzip flixel2.zip $ mv AdamAtomic-flixel* flixel
And let’s get a Flixel game: FlxInvaders is one of the Flixel examples, and the source is available.
$ wget --no-check-certificate -O flxinvaders.zip https://github.com/AdamAtomic/Flx-Invaders/zipball/master $ unzip flxinvaders.zip $ mv AdamAtomic-Flx-Invaders* flxinvaders
One final thing: Flixel is, by default, set up for Flex 4, and we’re
using Flex 3. So, you need to edit
there’s a section which looks like this:
// NOTE: Flex 4 introduces DefineFont4, which is used by default and does not work in native text fields. // Use the embedAsCFF="false" param to switch back to DefineFont4. In earlier Flex 4 SDKs this was cff="false". // So if you are using the Flex 3.x SDK compiler, switch the embed statment below to expose the correct version. //Flex v4.x SDK only (see note above): [Embed(source="data/nokiafc22.ttf",fontFamily="system",embedAsCFF="false")] protected var junk:String; //Flex v3.x SDK only (see note above): //[Embed(source="data/nokiafc22.ttf",fontFamily="system")] protected var junk:String;
and as per its instructions, comment out the Flex 4 line, and uncomment the Flex 3 line.
Now you’ve got everything you need to build FlxInvaders, the game!
Building a game with Flex
This bit’s easy; everything’s set up, so now you can just build the game
with one command. We need to call
mxmlc, the compiler, and since the
flxinvaders source requires flixel, we need to tell it where flixel is.
$ cd flxinvaders/src $ ../../flex_3_opensource/bin/mxmlc -compiler.source-path=../../flixel FlxInvaders.as
Lo and behold, you should now have
FlxInvaders.swf, which is your own
copy of the FlxInvaders game, built on Ubuntu with open source tools.
Simply load that swf file in your web browser to play. Hooray!