All 1 entries tagged As3

View all 2 entries tagged As3 on Warwick Blogs | View entries tagged As3 at Technorati | There are no images tagged As3 on this blog

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:

package
{
    import flash.display.*;

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

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

-optimize=true
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.

-static-link-runtime-shared-libraries=true
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-player=10.0.0
Target Flash Player 10 rather than the default Flash Player 9. Depending on the libraries you are using you can omit this.

-compiler.debug=true
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:

-compatibility-version=3.0.0
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.

IDEs

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.)
Flixel
PushButtonEngine

Physics:
Box2D
Nape

Tweening:
TweenLite

Sound effects:
as3sfxr

Misc. utility functions:
as3corelib

Statistic logging:
Playtomic

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.


New blog location

After a hiatus of several years, I’ve started blogging again at blog.draknek.org.

My website

Looking for more information about Alan Hazelden? Follow me on Twitter or go to my website.

December 2014

Mo Tu We Th Fr Sa Su
Nov |  Today  |
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 31            

Search this blog

Blog archive

Loading…

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

Tags

RSS2.0 Atom
Not signed in
Sign in

Powered by BlogBuilder
© MMXIV