January 21, 2011

AS3 Flash dev in Linux

It is possible to create Flash applications from Linux using only free tools. It’s also easy!

Downloading the Flex SDK

The Flex SDK contains the compiler you’ll be using. Flex is also the name of Adobe’s Flash-based UI library but you do not need to use any Flex components to use the Flex compiler.

You can find it easily by searching for “flex sdk”. At the time of writing the most recent version can be found here: http://www.adobe.com/devnet/flex/flex-sdk-download.html.

Older versions can currently be found here: http://sourceforge.net/adobe/flexsdk/wiki/Downloads/. You want to get the “Adobe Flex SDK” rather than the “Open Source Flex SDK” because the Adobe one comes with the debug flashplayer program you’ll be wanting to use for testing.

Using the command-line compiler mxmlc

MXML is an XML schema for laying out UI components, but you don’t need to (and don’t want to) create any mxml files to use the compiler mxmlc.

The executable is in the Flex download in flex/bin/mxmlc. The minimal usecase looks like this:

mxmlc Main.as

Which creates a file Main.swf. A minimal Main.as might look like this:

    import flash.display.*;

    [SWF(width = "640", height = "480")]
    public class Main extends Sprite
        public function Main ()
            graphics.drawCircle(320, 240, 100);

Generally you will want some give mxmlc some extra parameters though. I generally use these:

mxmlc -optimize=true -output $OUTPUT -static-link-runtime-shared-libraries=true --target-player=10.0.0 -compiler.debug=true Main.as

I’ve heard this doesn’t do a great job of optimising, but no reason not to include it really.

-output $OUTPUT
Specifies the filename of the SWF to be generated.

Starting with Flex 4 I get warnings if I don’t include this parameter, and in some projects the application didn’t run at all without it.

Target Flash Player 10 rather than the default Flash Player 9. Depending on the libraries you are using you can omit this.

Generates debug information so you can get line numbers from stack traces. You probably want to disable this when compiling your final release.

You might also want to be aware of:

Flex 4 has an incredibly annoying backwards incompatibility with Flex 3 where embedded fonts will silently fail and no text is rendered. This is one solution to that problem, the other is to add the parameter embedAsCFF="false" to all font embeds in your code.

-frames.frame arbitraryframename ClassName
This is used when you have a preloader. I won’t go into the details of using a preloader here, but when I compile with a preloader I use mxmlc [normal parameters] Preloader.as -frames.frame mainframe Main which compiles Preloader.as and Main.as separately.

Testing your SWF from the command line

The Adobe Flex SDK (but not the open source Flex SDK) comes with a debug version of the Flash Player that will show error messages.

It is located in flex/runtimes/player/10/lnx/flashplayer.tar.gz

Note that there should be two versions included: 10.0 and 10.1. I have not been able to get the 10.1 player to output trace statements so I use the 10.0 player for debugging.

After you’ve extracted it, you can test your application from the command line by running

flashplayer Main.swf

Improving build times

You might notice that compiling using mxmlc takes a very long time. This is because it has a lengthy startup time and doesn’t keep anything in memory for future compilations.

There is another tool in the Flex package to help solve this problem called fcsh (the Flex compiler shell). Running fcsh will give you a shell, and typing mxmlc commands into that shell will cache some results for improved speed.

Unfortunately this is a horrible way to work: you don’t want to use a specific shell for compiling, you just want a standalone command that can be run from bash, or from a makefile, or from wherever.

To solve this problem I wrote fcsh-wrap. You use it as a drop-in replacement for mxmlc and it will use black magic to speed up your compile times.

There are also similar scripts available for emacs which I have not used, and hopefully any AS3-supporting IDE will have fcsh support built-in.

Update: if for whatever reason you can’t or don’t want to use fcsh or fcsh-wrap, setting -incremental=true will give you some of the same performance benefits, although it will still be slightly slower.


Speaking of which, what AS3-supporting IDEs are there for Linux?

Obviously you don’t need an IDE because I’ve been talking about the command-line compilation toolchain. You can use any text editor you like: personally I use Sublime Text, obviously the vi/emacs fans will choose to use vi and emacs.

For Sublime Text, you want to install the ActionScript 3 package through this package manager.

For gedit, you can get AS3 syntax-highlighting support from here.

In terms of actual IDEs, there seem to be two choices. They both have a pricetag attached, but I believe they are both free for students or for development of open source projects.

IntelliJ IDEA is a Java-focused IDE, but the Ultimate edition comes with AS3 support. Comes recommended by Daniel Cassidy.
FDT is a Flash-focused IDE. Looks worth checking out but I have no personal experience of it.
FlashBuilder is Adobe’s product. It is essentially an Eclipse plugin. Correction: FlashBuilder is no longer available for Linux

Useful AS3 libraries

This isn’t Linux-specific of course, but I think it’s relevant and useful to mention these here.

I was going to go into detail about why these are useful, but for the purposes of saving time I will just give you a list:

Game frameworks:
FlashPunk (Use this one! Also use my branch, it generally has a few more bugfixes and features than the official version.)



Sound effects:

Misc. utility functions:

Statistic logging:

Embedding your Flash application in a webpage

Again not Linux-specific but someone mentioned that this would be useful information to include.

I tried to embed the cross-browser SWF embed code into this post but it screwed up. Have a look at the SWFObject documentation (the “static publishing” section): you only really need step 1. Doing steps 2 & 3 as well will let you detect whether the user has the right version of Flash installed.

Note that the SWF is embedded twice (for different browsers) so if you change its filename or its size, you need to change that in two places.

And that’s it!

I think that’s everything that you’ll find useful. I’ve been making Flash games in Linux for over a year and a half now and I’m really happy with the tools available. Hopefully you will be too!

If anything here is unclear or you’re having trouble getting it set up, leave a comment below or send me a message on Twitter.

- 8 comments by 1 or more people Not publicly viewable

[Skip to the latest comment]
  1. GBGames

    Thanks for posting this! I was interested in doing Flash game development with the least amount of proprietary tools, but between figuring out a lot of the details and internals while also learning AS3, I decided it would take too long. I’m keeping this page bookmarked in case I ever decide to check out Flash development again.

    21 Jan 2011, 20:01

  2. LinuxGames

    Great post, a small update in the IDE section:
    According to http://labs.adobe.com/technologies/flex/flexbuilder_linux/
    Adobe will no longer be investing in the development of a version of Adobe® Flex® Builder™ or Adobe Flash® Builder™ that runs on Linux operating systems.

    21 Jan 2011, 21:39

  3. allinlabs

    Also, for a Vim syntax highlight, you can download this file : http://www.vim.org/scripts/script.php?script_id=1061
    You put the file in your $VIMRUNTIME/syntax/ (example : ~/.vim/syntax/ )
    Then add this 2 lines to your ~/.vimrc :

    autocmd BufRead,BufNewFile *.as set ft=actionscript
    syntax on

    Hope it’ll be useful for someone else. Worked for me.

    And thank you again Draknek

    21 Jan 2011, 22:22

  4. Alan Hazelden

    Thanks for that update on FlashBuilder. I don’t know why they can’t offer it any more, I thought it was just an Eclipse plugin…

    21 Jan 2011, 22:41

  5. Billy

    Regarding “Improving build time”, the incremental=true flag is very helpful for reducing the time on successive compilations (it will only rebuild what has changed)

    22 Jan 2011, 00:42

  6. Alan Hazelden

    Billy: fcsh does incremental compiling and also has other speed improvements too. But if you’re in a situation where you can’t use fcsh that would be a good second choice.

    22 Jan 2011, 01:02

  7. Billy

    Right, but I was mentioning it per “Unfortunately this is a horrible way to work”
    Fsch-wrap is useful, it’s nice that you’ve written it! But that doesn’t mean one shouldn’t understand how their environment works….what would we have done if we didn’t have your script, a script you’ve got to admit is relatively unknown as of yet :)

    09 Feb 2011, 00:11

  8. Duncan Beevers

    I recommend checking out Project Sprouts from Luke Bayes. It makes obtaining and configuring the flash build tools trivial across multiple platforms. It also helps to eliminiate duplication in build scripts, facilitates test-driven development, debugging and continuous integration.

    09 Apr 2011, 01:32

Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.


My website

Looking for more information about Alan Hazelden? Follow me on Twitter or see my website for my games and my physics engine.

January 2011

Mo Tu We Th Fr Sa Su
Dec |  Today  | Feb
               1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30


    Search this blog

    Blog archive


    Most recent comments

    • Knife game: No actual cutlery involved. A single player starts with the "knife" by clasping his or h… by Noyb on this entry
    • My friends and I have taken to this one very silly game lately that's probably altogether too insula… by Ian S. on this entry
    • Great, thanks for those! That first one I would know by the name of Wink Murder, usually with a sing… by Alan Hazelden on this entry
    • I don't know the names for these games, so I'll make them up: Sniper. Randomly choose who is the sin… by zep on this entry
    • I recommend checking out Project Sprouts from Luke Bayes. It makes obtaining and configuring the fla… by Duncan Beevers on this entry


    Not signed in
    Sign in

    Powered by BlogBuilder
    © MMXIV