Recently in ActionScript Category

Porting FC64 to Android via Adobe AIR

| No Comments | No TrackBacks
A long, long time ago on an Internet far, far away, Claus Wahlers and I collaborated to create FC64, a low level Commodore 64 emulator written in ActionScript 3.  I remember first talking about FC64 at FITC, and I first blogged about it back in May of 2006.

FC64 is a side project of ours that, like the cobbler's kids who never get shoes, never seems to get the attention it deserves.  The TODO list hasn't been chipped away at in a long time, and there are still some glaring omissions (the most obvious being sound emulation).  There's a nagging decimal mode bug in the CPU that still needs to be fixed.  The code has been lost, found, moved around a few places, survived a hard drive failure, but eventually made it's way to where it's been dormant for, well... a long time.

However, all of that changed this weekend when my Nexus One arrived.

So far I've been doing all of my Android development with the native Java SDK testing on a Motorola Droid, but the Nexus One gave me a chance to install Android 2.2 and the AIR runtime.  This provided me an opportunity to take a deep, hands-on dive with with the AIR for Android beta.

Naturally, the very first thing I did with it was to try and get FC64 running on the device.  I tweeted about it quickly on Saturday and included a very poor screenshot, and Scott Janousek picked up on it and relayed the news around on his weblog.  I was a little embarrassed that not only did I have a typo in the tweet that was going around (as an aside, Twitter as a stream-of-thought medium for me tends to be much more raw than an article/post/entry), but that the screenshot was such poor quality.  It literally was the very first build though, and I was excited to at least get that far.

Since then I've had the chance to bring FC64 to a point where I would officially call it "working" on Android 2.2 via AIR.  Here are a few screenshots that illustrate the current progress of version 0.0.1 (click images for larger versions):

These two images show FC64 loaded in portrait mode using the native on-screen keyboard to enter commands. This shows the result of running a simple POKE command.

FC64 in landscape mode playing a game.
Here we have a game running in landscape mode with the virtual keyboard hidden.

For the most part it was straightforward and easy to port our 4-year-old ActionScript project to Android via AIR.  Here is the short list of things that needed to be done:

  • Installing the AIR runtime on my Nexus One
  • Creation of a separate AIR project in FlashBuilder with a device-specific main runner class
  • Addition of code to handle screen orientation changes
  • Refactoring of code to handle keyboard input
  • Added support for trackball to act as a joystick
  • Creation of a build script to compile, package, and install the application on my phone
Everything else worked out of the box without modification.  I did make a few minor changes to the base code in order to improve performance just a little.  For example, we were originally dispatching a lot of events for tracking frames per second, but new Event() at short intervals has a lot of overhead on mobile and was slowing down the emulation.  This will probably be refactored again into a conditional compilation directive.

I also took some time to wire up the Nexus One trackball so that it can be used as a joystick.  In Galaga, for example, scrolling the trackpad will move your ship left and right, and pressing the button down will fire.  It's a nice addition and fun for games.

There is still a lot that needs to be done, both for the Android application and for FC64 in general, but I was pleasantly surprised at how quickly I was able to get an initial port of the code base running on my device.

A short Android-specific TODO list for FC64:

  • Load ROMs from SD card.  Currently I've hard-coded the public domain game Galaga into the application.  Pressing the Android "back" button will load the ROM and start it automatically, or, if the ROM has already been loaded, it will reset the CPU.
  • Further optimizations such as using Joa's TDSI and Memory class to improve performance (both for mobile and in general).
  • Update the visual display.  Currently we're scaling the renderer to match the width or height, but it degrades the C64 text.  We might remove the scale and just center the renderer for a crisper display.
  • Proper key mapping.  This wasn't so apparent on the desktop version, but the virtual keyboard on mobile doesn't allow you to press "shift + 2" which is required for entering the " symbol (the original C64 keyboard had " as shift + 2) so BASIC commands are hard to enter.
I plan on pushing the source for this into my GitHub repository at in the next day or so, and I'll propagate the changes upstream to the master repository.


AS3 JSON library now a little less strict

| No Comments | No TrackBacks
I've just checked in revision 83 of as3corelib that adds a strict flag to the AS3 JSON library.  In the past the library would generate an error if the JSON string was deemed invalid according to the syntax rules.  Now, based on the strict flag setting, the parser does a better job at allowing "valid" input even if the input doesn't match the JSON spec.

I've actually had this code completed since MAX 2008.  I wrote it on my flight from San Fransisco to Harrisburg, but haven't had the time to get it ready for check-in until now.

Here is the commit message:

  • Added throwing error if entire string cannot be consumed (when there are remaining characters left in the input stream)
  • Added "strict" flag to decoding process.  Default is true for backwards compatibility.  When false, relaxes input format rules.  Fixes #34, Fixes #41, Fixes #71:
    • Allows for hex specification for numbers, ex: { "myNum": 0xFFCC33 }
    • Allows for NaN to be parsed as a number, ex: { "myNum": NaN }
    • Allows for trailing commas in arrays, ex: [1,2,]
    • Allows for trailing commas in objects, ex: { "p1":true, "p2":false, }
    • Does not throw error if there were characters left in the input string
  • Added tests for strict flag
  • Added tests to better exercise comments
  • Updated tests to use proper assert types
  • Some minor cosmetic code cleanup
Usage is exactly the same as before, with the additional option of specifying the strict flag as part of the JSON.decode( string, strict ) call.  Example:

// Set strict mode to false to allow for trailing commas to not throw an error
var o:Array = JSON.decode( "[0,1,]", false ) as Array;
assertEquals( 0, o[0] );
assertEquals( 1, o[1] );

// Same usage as before, strict mode will throw a runtime error if the string is not valid
var a:Array = JSON.decode( "[0,1,]" ) as Array;

I still need to address #35 to allow for unquoted keys in objects to be parsed in non-strict mode.  This is a bit more complicated of a change because it changes how the tokenizer recognizes what is in the input stream.  It's coming though!

Note that a new .swc file was not yet posted.  If you want to experiment with these changes, you'll have to pull the latest from source.  I'll work with Mike to get the download .swc updated soon.

New Chart Annotation added to FlexLib

| No Comments | No TrackBacks

I've added a new chart annotation, HorizontalAxisDataSelector, to the FlexLib project.

The HorizontalAxisDataSelector is a relatively simple chart annotation that allows a user to select a value along the horizontal axis of the chart. When the uses mouses down on the chart, the selector dispatches a change event and draws a vertical line at the nearest data point along the x-axis.

The selector contains a dataValues property that is an array containing the y value of each chart series at the given x-axis location. You can use these values to present a clear view to the user of all of the y-values for a given x-value rather than forcing them to rely on mousing over data tip points.

You can view the example here, along with the example source code.

Integrating the chart annotation basically just involves adding the following to your chart:

	<flexlib:HorizontalAxisDataSelector id="dataSelector"
		selectorColor="0x000000" />

This is something I wrote a really long time ago, probably on the order of 6 months or so (6 months is like an eon or two in internet-time). It's nothing special by any means, and is still rough around the edges. I had wanted to re-visit it and make some improvements, but just haven't found the time to work on it. As such, I figured it was best to just publish it since it's actually proven itself useful a few times, rather than hold on to it waiting until I have the time to get around to updating it.

In its current form, you can only use this annotation on horizontal axes that are numeric (or date-driven), and that are in ascending order. Kind of a bummer, I know. If you need to use this on a category axis, feel free to modify the source and contribute it back into FlexLib once you get it working!

Note: Right now this is only available in SVN. Doug and I are still sorting out when the best time is to create new packaged FlexLib .swc releases.

On a related note, this annotation isn't nearly as cool as some of the annotations Ely has come up with. His Chart Sampler is amazing. My meager annotation barely scratches the surface of what is possible in the charting framework. To this day I'm still amazed at just how flexible and extensible the charting framework is...

Announcing as3cards Google Code Project

| 4 Comments | No TrackBacks

I'm pleased to announce that I've got the as3cards Google Code Project up and running. The as3cards project provides a skinnable ActionScript 3.0 card engine for creating playing card games, with an example implementation of Klondike Solitaire.

You can view the example implementation of Klondike here.

This is essentially a continuation of my over-a-year-and-a-half old ActionScript 3.0 Klondike game, that was showcased on labs back in the early days when we still had Flash Player 8.5.

Originally I had included this in IFBIN. When IFBIN disbanded I wasn't sure what I wanted to do with the code. I spent a lot of time writing it and wanted to try to get something out of all the time that I put into it, so I didn't want to just blindly release it as open source.

Time passed, and I become involved in a lot of other work as my consulting business really picked up. The Klondike code was left to gather dust on my hard drive. After mostly forgetting about it, I've been contacted by a few people recently that put it in the front of my mind again. I figured that since it's been so long and I haven't done anything with the code yet, I might as well just put it out there as open source and let others run with it.

So, I went through the (very old) code base and updated it to work with the latest build of Flash Player. I've committed the source code into the as3cards Google Code Repository, and released it under the MIT license.

Also, I've built a simple Flex 2 shell that loads the ActionScript-only game and plunks it on the stage. You can use as3cards in both ActionScript-only (plain ol' Flash) projects, or you can inject the card engine into a Flex application.

This project was somewhat hard to part with because of my time invested in it, and the potential market of selling it to people that want Flash poker sites... but in the end, I think this is the right decision and I hope that you find it useful. If you'd like to help contribute (with maybe a FreeCell implementation, or a new skin, or anything), let me know. Donations (and/or ad clicks) are welcome, of course, but not expected.


Over the past few weeks, we've been silently moving the Open Source ActionScript 3.0 Libraries from Adobe Labs to Google Code. I'm happy to announce that we put the finishing touches on everything last night, and we're now open for business.

As Mike Chambers mentioned, the reason for the move is because Google Code offers a better infrastructure for the projects. We now have a mailing list, wiki, and issue tracker for each of the individual libraries. More importantly, other developers will find it easier to contribute. For example, Owen van Dijk recently added Uploading support into the Flickr API.

The projects now on Google Code are:

I'm very excited about this move. I hope it can breath new life into the libraries as more people get involved and more transparency is introduced. If you are interested in contributing to any of the projects (either writing code, doing testing, writing documentation on the wikis), sign up on the appropriate project mailing list and offer to help. Also, feel free to log any bugs or issues you may run into on the issue trackers (but search before you post, so we can avoid duplicates!).

Thanks to Mike, Mike, and Charles for helping to make this move a success!

ActionScript 3.0 Tip: Date Constructor

| 1 Comment | No TrackBacks
If you're doing a lot of work with dates, you might be able to make your life easier by taking full advantage of the Date constructor.

The documentation for the Date constructor lists the values that you're allowed to use when constructing a new Date instance. For the values of month and date, the valid range of values is limited to a small subset of positive integers. The month value can be 0-11 (0 = Jan, ..., 11 = Dec), and the date value can be 1-31, depending on the number of days in the month.

What the documentation doesn't tell you, however, is that you can pass pretty much any number for month and day, and still get a valid date back. This is really useful when trying to figure out some specific date values...

The following code block shows some different usages of the Date constructor, and the resulting Date that was created:

// This creates a date with a month value of 1 before January
// in 2006.  The resulting date is Dec. 1st, 2005.
var dt:Date = new Date( 2006, -1, 1 );
trace( dt ); // Thu Dec 1 00:00:00 GMT-0500 2005
// This tries to create January 0th, 2006, which is the last
// day of the prior month.  In this case, we get a date
// of Dec. 31, 2005.
dt = new Date( 2006, 0, 0 );
trace( dt ); // Sat Dec 31 00:00:00 GMT-0500 2005
// March 0th doesn't exist, so this will actually create a date
// that is the day before the 1st of March.  In this case, the date
// is the last day of February in 2008.  You can see by the output
// that this gives 29, indicating 2008 is a leap year.
dt = new Date( 2008, 2, 0 );
trace( dt ); // Fri Feb 29 00:00:00 GMT-0500 2008
// Create a date that is "a week ago from today"
dt = new Date(); = - 7;
trace( dt ); // Fri Dec 22 09:54:20 GMT-0500 2006

Using this concept, you can easily create a function to return the number days in any given month. To get the number of days in Feb. 2008 we simply asked for the "0th" day of Mar. 2008.

You can apply this same technique for time values as well. For example:

// The -1 for the hour gives us an hour before 0:00 on Jan 1st 2006, which is
// 11 pm on Dec 31 2005.
var dt:Date = new Date( 2006, 0, 1, -1 );
trace( dt ); // Sat Dec 31 23:00:00 GMT-0500 2005

This really isn't any new information and has been covered in the past in various other places. However, with the amount of new people coming into Flex 2 and ActionScript 3, I thought it was worth mentioning for those that might not be aware, especially because the documentation doesn't mention this at all.

I was talking to a friend this morning, and this technique made his day (pun intended!).

Happy Friday!

Compile ActionScript in ActionScript

| 1 Comment | No TrackBacks

If you haven't seen the Tamarin news by now, what rock do you live under? Did you catch the part about the new ActionScript compiler?

I don't want to rehash what's already been said. JD does a great job at the above link to send you to various places for background information, impact, etc. Instead, I want to point out something that could easily be missed in the announcement: Adobe has released a "self hosting" open source ECMAScript compiler.

As Tinic mentions, the AVM2 code does not include a compiler. Adobe has a Java compiler instead (which you can download free via the Flex 2 SDK) that was built to help support Flex Builder 2. The separate compiler keeps the AVM2 code size (and therefore, the Flash Player size) smaller, but it also means that "eval" doesn't work. The eval function takes an arbitrary string representing code, and executes it, such as eval( "x = 10; alert( x );" );

To combat this, enter the ECMAScript compiler, written in ECMAScript (ActionScript 3). Take a look at the code in this directory, and in particular the parser itself. It's an interesting piece of work, but is only partially complete.

It's exciting to see this in development. As this code matures, we should have available to us a runtime compiler that can interpret ActionScript 3 code on the fly. I'm not sure that I'd use it much in my daily Flex work (I haven't had the need thus far anyway), but I appreciate the effort behind this and am looking forward to seeing it in action.

Tags: , ,

Multiple Inheritance in ActionScript 3

| 11 Comments | No TrackBacks

Did you know ActionScript 3 supports multiple inheritance? Here's how...

Multiple inheritance is actually possible with AS3, despite popular belief that it's not supported. It's not really multiple inheritance in the true sense of the word going by the strict definition... but there's a way to get the job done in AS3 that behaves almost like the real thing.

What I'm about to show you is not something I would advocate as best practice. Nor is it something that should be (ab)used simply because its available. I'm not going to get into the debate about Composition vs. Inheritance and how Multiple Inheritance fits into the picture. If you're here, it's probably because you want to know how to use this technique. I assume you also know then the various repercussions (and if not, at least have the ability to google them). As they say, "with great power comes great responsibility".

Various disclaimers aside, here we go...

FC64 4 teh WIN!

| 2 Comments | No TrackBacks

Since the Flashfoward Film Festival is over, it's time to let loose the FC64 demo that netteed Claus and I a win for technical merit. Enjoy!

FC64 Demo

FC64 Demo Source Code

Fore more information about the demo, see my post here, and Claus' post here.

Sadly, neither Claus nor I could make it to Austin this year to pick up the award in person. I wish I could've been there to see the audience's reaction to the demo, and to accept the award live.

Since it was a joint project Claus will be the keeper of the orange rubber arrow, but I'm hoping to at least get visitation rights!

I'm pleased to announce FVNC, the rebirth of my FlashVNC project. The project is released as open source under the terms of the GPL.

I've updated the code to compile with the release version of Flex 2. Previously, the application was only functional in beta versions and stopped working when Flash Player 9 was officially released. I've also started to do some refactoring, but decided it was better to get the code out there as-is than keep it locked up while I tweak it. I've been beyond busy lately, and I don't see myself finishing this round of refactoring any time soon, so better to release now than wait a few weeks…

That said, keep in mind that FVNC isn't complete yet. There are a lot of items on my TODO list that need to get done before I would consider using this in a production application. The software is somewhere between alpha/beta quality right now, not entirely feature complete, rough around the edges, in need of some performance tuning, and in general still a work in progress.

If you're interested in contributing, please get in touch. Also, check out the mailing list if you're into that sort of thing. Everything you need to know about the project can be found (or will be found in the future) on the OSFlash FVNC page at:


About this Archive

This page is an archive of recent entries in the ActionScript category.

AIR is the next category.

Find recent content on the main index or look in the archives to find all content.


OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.02