This post originated from an RSS feed registered with Web Buzz
by Stuart Langridge.
Original Post: Using Flixel and Adobe Flex on Ubuntu 10.10
Feed Title: as days pass by
Feed URL: http://feeds.feedburner.com/kryogenix
Feed Description: scratched tallies on the prison wall
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 Adobeu00ae Flashu00ae Player and Adobe AIRu00ae 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 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:
...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.)
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!