Using Flixel and Adobe Flex on Ubuntu 10.10

Today’s experiment: using Adobe Flex on Ubuntu.

Adam Atomic, developer of the wildly popular Canabalt, released a game creation library that he built to make the game. It’s called Flixel. Now, Flixel is open source, and it’s in ActionScript, which is Adobe’s version of JavaScript.

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
This used to be called “Flex Builder”. It’s a graphical IDE based on Adobe’s Flex, a “highly productive, free, open source framework for building expressive web applications that deploy consistently on all major browsers, desktops, and operating systems by leveraging the Adobe® Flash® Player and Adobe AIR® runtimes”. (Basically, it’s a thing that compiles XML and JavaScript to SWF Flash applets.) But I, personally, don’t like IDEs: I like writing code in gEdit and compiling it with a command line compiler. So…
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_3.4.1.10084_mpl.zip
$ mkdir flex_3_opensource
$ unzip -d flex_3_opensource flex_sdk_3.4.1.10084_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 /usr/lib/jvm/java-6-sun/jre/bin/java.

(We can now test that it works: run ./flex_3_opensource/bin/mxmlc and 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 flixel/org/flixel/FlxGame.as: 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!

More in the discussion (powered by webmentions)

  • (no mentions, yet.)