Setting up IntelliJ IDEA to develop with Flash & Molehill

Today I set myself the task of familiarising myself with Flash’s pre-release Molehill 3D graphics APIs. Three hours later, I had a colourful triangle that rotates about the z-axis, and a clear idea of how to proceed later when I want Molehill to do something cool.

Perhaps not surprisingly, I spent the majority of that time mucking about getting Flex and IntelliJ properly configured and playing nice together, so I thought I’d write down what I did in the hope that it helps someone else get started. You might still be able to pick up some tips even if you’re using another IDE (or, if you’re Draknek, none at all).

Note that Molehill is very much in a pre-release state, and nearly everything I say here is liable to change with future releases. So take it with a pinch of salt — I hope it’s helpful, or at least interesting, all the same.

1. Install the Flex Hero SDK

Flex Hero is the current in-development version of the Flex SDK, which will presumably be called Flex 4.5 when it’s done.

You need a pre-release Flex Hero SDK, build or later (direct link to that build). Read the download page carefully because the most prominent download on the page is for an earlier (but more stable) version that doesn’t include everything you need.

The Flex SDK is just a bunch of stuff in a zip file, so to install it simply unzip it somewhere sensible. That should be somewhere where you have write access without requiring administrator priviledges, to avoid any unnecessary mucking about later on.

If you’re like me and you use your own custom build of the Flex SDK branched from the public SVN repository, don’t do what I did and fall into the trap of assuming you can just do an svn update to get everything you need. Adobe are gits and don’t really understand the concept of ‘open source’. The public Flex SVN repository is currently at least 4 months out of date compared to Adobe’s internal SVN repository, and it doesn’t appear to include any of the changes destined for Flex Hero. I assume that Adobe won’t make the source code available until they’re ready to do a final release, so for now you have to download the binaries linked above.

2. Install playerglobal.swc for Flash Player 11

Flash Player 11 is the upcoming release of the Flash Player, which will include support for the new Molehill APIs.

Each version of the Flash Player has an accompanying playerglobal.swc file. The job of this file is to map calls to the AS3 API to the underlying Flash Player implementation. When new features are added to the Flash Player, you need a new playerglobal.swc to expose those features. Since playerglobal.swc is usually distributed with the Flex SDK, that process is usually transparent.

The Flex Hero SDK you’ve just downloaded does include a playerglobal.swc file as usual, but for some reason it corresponds to the current release Flash Player version 10.2, whereas we need version 11 in order to get the Molehill APIs.

To fix this, download the pre-release playerglobal.swc for Flash Player 11 (direct link to the required file).

‘Install’ the new playerglobal.swc by copying it into the Flex SDK. You’ll need to create a new directory at flex/frameworks/libs/player/11.0, where flex is the location where you installed the Flex SDK. Then copy the playerglobal.swc you downloaded into the new directory.

Note: There will already be an older playerglobal.swc at flex/frameworks/libs/player/10.2/playerglobal.swc. Just leave it where it is.

3. Install Flash Player 11

You can download a preview release of Flash Player 11 from Adobe Labs.

Due to an apparent lack of good judgement and forward-planning, Adobe have not (yet) seen fit to release a standalone Flash Player 11, so it’s necessary to install it as a browser plugin. This in turn means that it’s a pain to avoid using a preview release Flsah Player while doing general web browsing, which is not a particularly good idea.

My usual web browser is Chrome, which comes with its own Flash Player, so my approach was to install the preview release Flash Player for Firefox and use Firefox for development and Chrome for general browsing. This has the disadvantage that I spend most of my development time waiting for Firefox to start up and/or whinge about installing updates, but the advantage that I’m not browsing random websites with unstable software.

If you’re using Firefox to debug Flash applications, then you need to disable plugin crash detection, otherwise Firefox will decide that Flash has crashed if you spend more than 15 seconds in the debugger. Thanks to Mozilla for adding that feature without thinking about the debugging use case.

If you’re using Chrome to debug Flash applications, then you need to disable Chrome’s built-in Flash Player, and enable the external debug player. I don’t recommend doing this if you use Chrome as your primary browser, since you’ll lose automatic Flash Player upgrades. You’re better off using a secondary browser for development.

4. Set up a new project in IntelliJ

Set up a new project in IntelliJ as follows:

  1. File > New Project...
  2. Select ‘Create project from scratch’ and click ‘Next’.
  3. Name the project and make sure you choose to create an ‘ActionScript/Flash/Flex’ module, then click ‘Next’.
  4. The following screen asks where you want to place your source code — either leave it as the default or set up an alternative location as you prefer. Then click ‘Next’.
  5. Click ‘...’ next to ‘Module SDK’. In the resulting screen, register your newly-downloaded Flex SDK with IntelliJ by clicking the golden plus at the top-left corner, and choosing ‘Flex SDK’ from the list. Select the directory where you installed the Flex SDK and OK out back to the ‘New Project’ window.
  6. The new SDK should now be selected in the list. Next time you can just choose it from the list – you don’t have to register the SDK with IntelliJ each time.

    Set the target Flash Player version to ‘11.0.0’. This is important because otherwise IntelliJ will target the earlier version 10.2, which will disable the Molehill APIs.

    Make sure that ‘output type’ is set to ‘Application (*.swf)’. The other choices on this page don’t matter too much but I usually set them up as shown in the screenshot.

  7. When you’re done, click ‘Finish’ to create the project.

5. Disable IntelliJ’s built-in Flex compiler shell

By default, IntelliJ uses its own Flex compiler shell, which for some unknown reason can’t produce SWFs that can access the Molehill APIs. To work around this we have to configure IntelliJ to use the Flex compiler shell provided by the Flex SDK.

  1. File > Settings...
  2. Compiler > Flex Compiler
  3. Choose ‘Flex Compiler Shell (fcsh)’ and OK out.

Note that this is a per-project setting and won’t affect your other projects. You’ll have to perform this step for every project that uses Molehill.

6. Set up additional command-line options to the compiler

Finally, we have to trick IntelliJ into compiling for SWF version 13. We do this simply by adding the appropriate command-line option to ‘additional compiler options’ in the compiler settings.

  1. File > Project Structure...
  2. Ensure ‘Modules’ is selected on the left, and that your Actionscript module is selected in the middle column. 
  3. Choose the ‘Flex Compiler Settings’ tab.
  4. In ‘Additional compiler options’ at the bottom of the window, set:


Again this is a per-project setting, so it won’t affect your other projects and you’ll need to repeat it every time you set up a new Molehill project.

7. Write some code and run it

All set up! Now you just need to write some code that uses the Molehill API and run it. Maybe in the next few days I will write a simple tutorial for writing a minimal program using Molehill.

Don’t forget that you may need to configure IntelliJ to open the SWF in whichever browser you’ve set up with Flash Player 11. You can do this by going to Run > Run Configurations.


If the debugger logs out an exception complaining that Context3D or some other part of the Molehill API can’t be found:

  • Check that you’re definitely running in Flash Player 11. If you are, and it’s a preview build, you’ll see some text like ‘Adobe® Flash® Player 11 (11,0,0,58d) (Incubator build)’ at the bottom-right of your movie (this text will be removed in the final build of Flash Player 11). If you don’t see the text, you’re probably running an older version.
  • Check that you correctly completed steps 1, 2, 4, 5 and 6 above.

Moderately amusing story

Here’s a moderately amusing story for you chaps.

I was walking to work this morning, as I do every day. As I was walking towards the bridge over the railway line, I came across a rather rickety looking white van heading in the opposite direction. As it drove towards me it emitted a regular series of unhealthy-sounding noises: a sort of continuous, rumbling, droning sound; periodic squeaks and occasional clatters.

It all sounded suspiciously rhythmic, like some sort of underground dance music. It only took a few seconds for the van to pass me. It was definitely not playing music. I thought I must be cracking up. I could still hear it clattering down the road behind me as I approached the near side of the bridge.

Then, I passed the corner of a building on my left, and was nearly knocked over by the wall of psychedelic trance emanating from our friendly neighbourhood housing co-operative.

That would explain that then.

Game: Green Triangle Ship vs. Alien Chaos Spheres

This is a bit late because I’ve been exhausted, but here is the finished game George and I wrote for the Ludum Dare 18 Jam.

It’s a bit like Asteroids, but with less asteroids and more Alien Chaos Spheres. You can’t destroy the Chaos Spheres directly, but you can use your laser cannon to push them around. Knock two or more Chaos Spheres together and they explode in a shower of sparks while you score some points.

It’s Flash based, so you can play it online. Click on the game to give it focus, then use the arrow keys and enter to navigate the menu. Use the left and right arrow keys to rotate your ship. Tap the up arrow for forward thrust, and tap the down arrow for reverse thrust. Press x to fire your laser cannon.

Score disproportionately more points for destroying Chaos Spheres soon after they spawn, for destroying Chaos Spheres that are moving fast, and for destroying many Chaos Spheres in quick succession.

We built this in 48 hours over the weekend, or 72 hours if you count some abandoned changes made on the last day. Bearing in mind the short amount of time in which it was built, I’m rather pleased with the way it turned out, although it is a bit rough round the edges. We plan to clean it up and introduce an improved version in a few weeks (or months).

If you score more than about 2 billion, the score counter overflows and you get a negative score. If you achieve that then... er... you win! (It is actually quite possible to do this, if you’re good).

We built the game in the very pleasant surroundings of the CB2 bistro in Cambridge, accompanied by indie game developers from Cambridge and across the UK. Thanks to those guys for helping make it such a fun weekend, and thanks also to the CB2 staff for tolerating us for 14 hours two days in a row! I am particularly indebted to Alan for patiently reminding me how vector math works, and without whom the game would be a shadow of its eventual self.

Foolishly, I didn’t take any photos of the event, but I’m sure Alistair won’t mind if I borrow his montage:


I’ve only just noticed that Dock was wearing a Rez t-shirt. Awesome!

Playable Preview of our Game for Ludum Dare 18 Jam

Here’s a playable preview of our Ludum Dare Jam game.

It’s working and it’s almost fun. Just need to make some iterative improvements to the mechanics and aesthetics.

Use your laser cannons to push the balls around. Knock two balls into each other to destroy them and score points. You score more points for destroying faster moving balls.

Mayhem in Monsterland Premium Edition

One more post before I get some much-needed sleep.

I received a very cool thing in the post today.


That is a brand new, just manufactured, recently back in print, newly remastered 15th Anniversary Premium Edition of Mayhem in Monsterland, an absolutely classic, beautiful and hugely fun C64 game. On a 5.25″ floppy disk. A real floppy disk that’s actually floppy, as opposed to those 3.5″ solid plastic lumps.

Compared to the first time around, they’ve fixed a really annoying bug. That might sound like a minor thing, but the bug in question caused you to lose ten(!) lives if you were too good at the game, which was more than a minor irritation. It’s been really hard to get hold of a fixed copy until now.

Here’s an old video of me not-quite-perfectly completing the first level. (If you think the graphics look dreary, skip to 2:51 – and switch to 480p, damnit).

I am still rather miffed that they didn’t fix the bug properly 15 years ago, but better late than never. This game is too good to stay mad. I can’t play it until Ludum Dare is over, but Monday evening is going to be fun. It’s been a great weekend for games :).

Ludum Dare 18

I’ve just got home from CB2, where I have been participating in the Ludum Dare 18 Games Code Jam, in collaboration with George.

Between the two of us we’ve got 72 hours to build a working video game, which must relate to the theme ‘enemies as weapons’. We’re not entering the competition proper, otherwise we wouldn’t be allowed to collaborate and we’d only be allowed 48 hours.

Here’s a screenshot of our progress so far.


It’s a bit like Asteroids, except enclosed within a circular play area, and you can’t destroy the ‘asteroids’ directly. Instead, you can push them around by firing lasers at them. To destroy the ‘asteroids’ and score, you must collide them with each other – hence ‘enemies as weapons’.

Given that we’ve only been working on it since 10am, I’m pretty pleased with our progress. The game is basically playable, there are sound effects in most places where you’d expect sound effects, there’s a scoring system that even I’m happy with, and I even wrote a little bit of ‘music’, but I’m not sure if I’ll put it in since it’s painfully repetitive (like all my music). The only major remaining gameplay issue is that sometimes an ‘asteroid’ will spawn on top of your ship and destroy it without warning, but that’s actually easy to fix. Once we’ve fixed that, we intend to introduce some new mechanics to make the game more interesting – and more challenging as it progresses.

Frustratingly I spent about three hours today trying to make the ship and ‘asteroids’ bounce off the arena wall in a convincingly elastic fashion. The eventual code to implement that was about four lines long. One and a bit lines of code per hour is not particularly good going when you’re working to a deadline. I owe a debt of gratitude to Alan who gave me a hand with my dodgy vector math code, which got the bouncing working as expected. Other than that, everything has gone surprisingly swimmingly.

If you’re code inclined, you can follow our progress on GitHub. If you want to build the code, you need Flex and a little bit of nous. There’re no build instructions because, until the contest finishes, we have better things to do!

I have to say that a lot of the other entries are looking absolutely amazing, given that they’ve only seen a day’s work. I’m eagerly anticipating the finished products!

(Semi-crossposted to the Ludum Dare blog).

swfmill 0.3.1 released

Today I’ve released swfmill 0.3.1.

swfmill is a tool that can decompose Flash movies (‘SWFs’) into an XML representation of the contents of the movie, and back again. If you know what you’re doing, and have some understanding of the SWF format, it’s just about practical to view and edit the resulting XML by hand. Alternatively you can use the built-in XSLT processor to modify SWFs programmatically, or generate SWFs from arbitrary XML data sets.

swfmill was originally written by Daniel Turing, but I’ve been irregularly maintaining it since June last year. Thanks to Chris K for bugging me to do another long-overdue release :).

New in this release:

  • Official Mac OS X binaries (Intel-only, sorry!).
  • Fix bad JPEG parsing code that would often get the image size completely wrong (thanks to Piers Haken).
  • In simple dialect, automatically detect the number of frames in a movie clip (‘frames’ attribute now optional).
  • Fix invalid SWF generation when embedding some fonts.
  • Support alternate text encodings in SWF (useful only in SWF 5 and below(!), and only if you know what you’re doing) (thanks to INADA Naoki).
  • Some changes to make compiling on Mac OS X (and in general) a little easier.

Download it from