AS3.0 Abstracts


Another thing I needed was a strict abstract class in AS3, again, public only constructors, and the absence of the “abstract” keyword from ActionScript meant a workaround.

[as]
package
{
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;

public class AbstractExample
{
public function AbstractExample()
{
if( Class( getDefinitionByName( getQualifiedClassName( this ) ) ) == AbstractExample ) throw new Error( ‘AbstractExample must be extended’ );

// rest of constructor here…
}
}
}
[/as]

I like this solution best as it doesn’t rely on strings for comparison as in Tink’s example. His method is shorter, and easier for typing. It’s down to personal preference really.

AS3.0 Singletons


While I’ve been getting up to speed with my AS3 over the past few months, there have been a few things which are really useful to know and took a bit of digging about to find.

As class constructors in ActionScript 3.0 must be public, there’s not a really clean way to force a class to be a singleton as there is in ActionScript 2.0 or Java say.

[as]
package
{
public class Singleton
{
public static var instance:Singleton;

public static function getInstance():Singleton
{
if( instance == null ) instance = new Singleton( getInstance );
return instance;
}

public function Singleton( caller:Function )
{
if( caller == Singleton.getInstance )
{
// instantiate class here
}
else
{
throw new Error( ‘Singleton is a singleton, use getInstance();’ );
}
}
}
}
[/as]

It’s pretty simple, you can’t call new Singleton() because the compiler will be expecting an argument, and if you do pass an argument, it will throw an Error because the caller is not the Singleton.getInstance method.

So you can only access this class by calling Singleton.getInstance().

Polar Clock 3.0 development


pc3.jpg
Just an update of how the development of the next release of the clock is going.

I’ve ported 90% of the engine to actionscript 3.0 now, and begun implementation of a config panel built using Flex Builder 3 (Moxie). I’ve now got the following language implemented: English, Afrikaans, Chinese, Danish, Dutch, French, Finnish, German, Greek, Hungarian, Italian, Japanese, Korean, Norwegian, Portugese, Portugese (Brazil), Polish, Romanian, Russian, Spanish, Swedish, Slovakian, Thai, Turkish and Vietnamese.

I have spoken to a guy at ScreenTime (who make screentime for flash) and they are sending me an updated version for windows in a couple of days, to match up the sizes of the config panels with the latest release for mac. Yeah, I bought screentime for mac + windows!!!

I’m hoping to launch version 3 of the clock on of before 21/07/07. Keep checking for updates!

So far there have been over 40,000 downloads of v1 and 2, it’s much much more popular than I ever expected!

Polar Clock update


I’m currently working on sorting some issues with the current release of the Polar Clock. From comments feedback, it seems be an issue that the processor is under heavy use when the clock is running. Hopefully this will be aided by the porting of the existing code to AS3.

I’m looking into the following:

Using Chromo™ colours
Adding an options panel to allow turning on/off a millisecond ring, choosing different colour schemes, and lastly, choosing a locale. Also making the logo fade out after a while.

I want to add as many languages as I can get together. Help from you out there would be great.
Read more…

GammaSlamma


I’ve just discovered this little app! All you do is drag a png onto it, and it strips all the Gamma information out of the PNG file, which happens to make the colours perfect in Flash, and also takes a lot off the filesize.

I just processed a background image that was 116Kb and it came out as 63Kb!!!

Download it here

Polar Clock Screensaver


launch.jpg

UPDATE:
Version 3 is now available here

View Polar Clock

Download Screensaver for Mac OS X only.

I’ve just put this together as a bit of a test of some drawing API extensions I wrote a while ago. All the shapes are drawn with code, corner rounding curves are achieved using the ‘capStyle’ argument when setting the lineStyle, easy as that! The colour of each ring is based on an HSL colourwheel.

Commodore 64 Music


I was looking about for a C64 soundtrack today, from Last Ninja, and I found this.

First, you need SIDPlay (Universal for OSX) (c64 music was stored as .sid files), then download the massive High Voltage SID Collection.

SIDPlay will export to MP3/AIFF and even C64 executables (PRG).

Brings back some memories!!

Kernel Debugger


debugger
I’ve been using this for a long time now, it’s a debugger that runs in another SWF and is passed trace statements via my Debug class, with different levels or detail, info, warning, event, classinfo, error etc. It also has a runtime monitor graph at the bottom, the yellow line showing the current framerate, and the blue line showing the time it takes to execute all threads currently running in the Kernel class. The Kernel is basically a single onEnterFrame on a MovieClip in the _root, which runs through an array of threads, I simply have a getTimer() at either side of the thread execution and time it, this is a great way to view code-weight, especially when developing games or persistent enviornments such as physical engines.

I will make a public release of the Kernel, Thread and ThreadGroup classes soon, which will also include the debugger.

2D Physics API


I’ve recently been doing some games work that required some pretty full on physics, after battling with vectors and collision reflection on wheels and other objects, I ditched what I had done and am now working with FlaDE (Flash Dynamics Engine) an AS 2.0 GPL Licensed API. It’s written by Alec Cove, and is very easy to use. It never went to final release, and he has now moved on to APE (ActionScript Physics Engine) which is written instead in AS 3.0 and is again GPL Licensed.