Posted under ActionScript 3.0.

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…

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.