EDIT: This guide still seems to get a lot of attention but it should go without saying, at this point it’s a bit outdated. The ant flex tasks and the standalone Flash player are now included with the Flex 3 SDK for one thing. I don’t use Eclipse and fdb anymore myself since I learned to dislike Eclipse and the debug version of the standalone Flash player will dump trace messages to stdout (so it will appear in a terminal).

This guide isn’t particularly definitive, mostly because right now all the tools needed lack real cohesiveness, paticularly on Unix. This is simply how I pulled everything together to make things work using freely available software.

Step 1: Get Eclipse

Download Eclipse. Put it somewhere. If you’re using Linux, install using it using your favorite package management software. This guide will probably only work if you use 3.2 or above. (NOTE: If you use Ubuntu for this, then at the time of this writing Eclipse 3.2 is only in the “universe” repository, you can enable “universe” using Synaptic)

Step 2: Pull Flex together

Download the Flex 2 SDK. You’ll probably need to sign up for an account. Extract it. Download the Flex Ant Tasks and extract flexTasks.jar (in lib) to lib in your Flex directory.

You’ll need to set up the standalone player so you can debug your swf files. This varies between Operating Systems…

  • Linux: Download the Linux Flash Players and extract the debug player (in standalone/debugger/flashplayer.tar.gz) to bin in your Flex folder. Rename the the debug player (which is named flashplayer) to gflashplayer. You can also install the debug plugin for browsers if you’d like.
  • Windows: Run SAFlashPlayer.exe (in your Flex directory, under player/debug/) and it will register itself as the debug player. There’s also two installers for debug plugin if you care to install them too.
  • OSX: Use SAFlashPlayer.dmg (in your Flex directory under player/debug/) to install the debug player. There’s an installer for debug plugin there too.

Step 3: Create a project

Create a general project in Eclipse and put various Actionscript-related files there. Create a file called build.xml. This will be your Ant build file, and what you’ll use to compile your project. There’s more details on Ant here. Here’s a sample…

<project name="sample" basedir="." default="build">

<property name="FLEX_HOME" value="/path/to/flex"/>
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/lib/flexTasks.jar" />
<target name="build" description="Build">

<mxmlc file="example.as" output="bin/example.swf" use-network="false" compiler.optimize="true">

<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<source-path path-element="/path/to/as3-library"/>

</mxmlc>

</target>

</project>

The taskdef entry and the FLEX_HOME variable need to be there in order to use the mxmlc task to compile swf files. On Linux the property use-network="false" mysteriously allows the compiled swf to access files on your computer, without it an error is thrown when you try to access a file

Step 4: Syntax Highlighting (optional)

There is no free Actionscript 3 syntax highlighter, and the only one for Actionscript 2 is poor (sorry guys). Luckily Actionscript resembles heavily resembles Java. Simply associate .as files with the Java Editor in Eclipse (Window->Preferences, then General->Editors->File Associations) and hope nobody notices.

  • To change the formatting (particularly tab width) go to the Formatter (Java->Code Style->Formatter) and toy with the settings until it looks like your preferred coding style.
  • To change the colors go to the Syntax Coloring section (Java->Editor->Syntax Coloring)
  • To prevent Java from making suggestions, go to auto-activation (Java->Editor->Content Assist) and remove any characters in the “Auto activation triggers for Java” section.

Step 5: Compilation

Open the Ant viewer in Eclipse (Window->Show View->Ant) and drag your build.xml file to it. Use it to run build files.

Step 6: Debugging Preparation

You’ll need another target in your build.xml used for creating a secondary swf for debugging.

<mxmlc file="example.as" output="bin/example-debug.swf" use-network="false" incremental="true" debug="true">

Run this target whenever you want to update the debug version of your swf. The debug="true" property needs to be there in order for it to work. Make sure the output/swf file has a different name than your optimized build since this version is purely for debugging and will be slower.

Step 7: Debugging

Open the External Tools window in Eclipse (Run->External Tools->External Tools…). Select “Program” and create a new configuration. Set “Location” to the location of fdb, the Flash debugger (it’s in your Flex directory, under bin). The working directory should be the location of your compiled swf files. The only argument should be the file name of the swf file you’ll be debugging.

Run the external tool configuration you just created (there’s a button for it on the toolbar) whenever you want to debug the swf. When you do a console will open up, and the debugger will start. The Flash Player window will open, but it will remain frozen until you type “continue” in the Eclipse console. All output (trace) will appear in the console. If you familiarize yourself with fdb you can make use of many more features. To stop debugging, type “exit” in the console or just close the player window and terminate fdb.

I've finally switched

January 24th, 2007

It’s true! But probably not to the OS you’re thinking of. I’ve switched to Ubuntu. Linux. I can scarcely believe it myself. I’ve left Windows behind, on the eve of Vista no less, to a free OS made by volunteers and a wannabe astronaut. I always knew I’d move away from Windows the second I got the chance, but I spent my time pining for a MacBook while ignoring the always-present installation of Ubuntu on my computer. Ubuntu was my rescue-OS, it saved me whenever Windows decided to stop working. I tried to use it once or twice, but the little things kept getting in my way. I wasn’t quite sure why I kept it around since Ubuntu became a live-cd and all I had to do was put the CD in the drive to rescue my files before reinstalling Windows for the 10th time.

It happened very suddenly. I downloaded a nifty virtualization (like emulation, but way faster) program for Windows called VirtualBox and loaded up my copy of the Vista beta CD which I had never gotten around to burning. Instead of becoming interested in Vista I became interested in abandoning Windows with the help of virtualization. Flash 9 wasn’t even out of beta for Linux yet, and I refused to make a switch without bringing Flash with me. VirtualBox had a Linux version, I thought I could bring any missing software with me through it. I loaded up my copy of Ubuntu.

I instantly noticed how pretty the OS was and how much they had cleaned it up since the day I burned a copy of “Warty Warthog” because I had grown to hate Redhat’s Fedora. Warty wasn’t as pretty as Fedora, but it didn’t require me to burn 5 CDs just to install the thing. I grabbed a Linux version of VirtualBox but it wasn’t as fast as the Windows version. This made no difference though, because the change had already begun. I noticed the little things that always irritated me about Linux, like how my beloved play/pause/stop/next/previous buttons didn’t work, or how the music players all sucked, and how there was always key software missing, all gone. It was all there. I easily added shortcuts for my media keys, I left behind Winamp after 7 years for Rhythmbox, Eclipse was already there and a Linux version of the Flex SDK and Flash 9 had arrived.

The thing that really strikes me is how smoothly everything operates. I’ve been using NetVibes as my Desktop because no Windows software ever did the job. Evolution, Ubuntu’s calendar/mail app integrates with the OS. When you click on the time you get your todo list along with a list of events and appointments for the day. There’s also Synaptic, which I always thought was nice, but I still hated being bound to it. Synaptic is a software library program that can install and update software available in special repositories. It’s interesting, but if you want software not in the library, it was always hell to get it install. Now any software that provides a .deb file is child’s play to install. It’s far easier to do things you never even thought you wanted to be easier, like making software startup when you log in.

Simply put, using Ubuntu is one of the most refreshing computer experiences I’ve had in a long time. It’s not perfect, for one thing all my emulators and music input plugins are stuck on Windows. There are some equivalents on Linux, but they’re mostly inferior. My USB Xbox 360 controller doesn’t work – although a driver will eventually turn up. All my PC games are lost back on XP, although I was never much of a PC gamer anyway and I can boot up XP for gaming. Skype is uglier on Linux, although it still works. My favorite browser, Opera, is slower on Ubuntu than Firefox so I switched browsers as well.

I guess what I’m trying to say is that switching to Ubuntu was easy and completely worth it, I just finally ran out of reasons to keep using Windows. I’ve always disliked Linux because I felt it ignored real usability in favor of programmer’s indulgences. Ubuntu seems to have mastered keeping the little things that irritate me under control. I’ll probably never buy that MacBook now, I don’t think I’ll be needing it.

Hi MXNA

January 23rd, 2007

After sleeping for countless hours last night I awoke to some cool news.

For one thing, I’m now on MXNA! I submitted myself on a whim a while back and when I didn’t get a response I assumed I just hadn’t been around long enough. Now I’m a card-carrying Flash blogger. Since I wanted to talk about any interest of mine – not just Flash-specific ones – I created a special XML feed for exactly that purpose. This feed will only deliver posts that fellow Flash developers could find interesting, and is the one that will be aggregated by MXNA. If you want the full BrokenBlog experience though, you’ll just have to subscribe to the complete feed.

WordPress 2.1 is out! I just upgraded and it seems pretty nifty so far, although its created some empty spaces on my site I need to fix. Since I can no longer use Windows Live Writer for posts (more details on that later) I wanted a more capable post editor which 2.1 provides. It even auto-saves posts now.

Javascript is Very Fast?

January 10th, 2007

Apparently my previous post was premature. My world has shattered and I have discovered the single most impressive example of Javascript. Ever. Considering that just this morning the very same event took place (but with Flash) this is one hell of a day.

It’s an emulator. In Javascript. Take a deep breath and let that sink in.

I really wish this guy would switch to Flash. I programmed in Javascript in the old days and it’s really no good for certain things. What those “things” are is vauge, but basically, writing emulators is one of those things. In any case, Flash got there first and FC64 is cooler.

Actionscript 3.0 is Very Fast

January 10th, 2007

I’m not sure everybody fully understands how fast Actionscript 3 is. Even saying things like “tenfold” are laughable. For one thing, I can’t tell how fast it is because the current game I’m toying with cannot be measured. All the code for an each frame (which is a lot) is run in less than a millisecond nearly 100% of the time. Compare that to 6 to 9 milliseconds from older games.

Let’s face it though, numbers don’t do this kind of thing justice. But this animation does (via gBlog). It’s the live 3D rendering of a several ships, with well over 8000 polygons. The speed seems to vary unpredictably, but usually sticks to around 13fps or 30fps on my computer. Compare that to the as2 example, which runs at 3fps while rendering less than 1000 polygons. It’s not just faster, it’s a different level entirely. The demo is not perfect, but the 3D quality roughly matches the original Playstation.

On a side note, I noticed the files (meshes) that the example uses are text files. If they used FZip they could’ve turned around 333KB of files into a single 55KB file, making it easier to put online rather than offering it as a download. Just a thought. 😉

Beware of Flash Hacking

January 3rd, 2007

I spotted this post (via Digg) this morning. It’s a guide to hacking high-score boards in Flash games and he knows what he’s talking about. He uses Flasm to disassemble and find information in a SWF file. All the more reason to make sure the methods you use for this kind of thing are carefully hidden.

I heard a great idea from someone named Dan on Flashcoders. Send fake variables alongside real ones when a score is submitted. It could get even better if you make them interrelated and sensitive to hacking – something involving bitwise math perhaps? You could also include checksums of course. There was also my idea to “record” user input (mouse movements, key presses, etc), encode it, and send that to a server. Then simply add in the ability to playback these recordings when you want to make sure they’re legit. It’s pretty tricky though, and could have lots of problems, for starters you wouldn’t be able to change your code without breaking old recordings and you can’t use Math.random().

While I don’t like this guy, it’s not as if these methods aren’t known already. Why did people have to digg it though? It’s cheating. What’s the point? I suppose Flash coders just have to get smarter when it comes to this kind of thing.