PolarClock on OS X Leopard

I’ve found a bug in screentime, the software used to pack up PolarClock as a screensaver. When run on Leopard, after the screensaver exits back to the desktop, the Function keys and any shortcuts to the Dashboard or exposé don’t work. I have contacted screentime about this issue, and will post a fix a.s.a.p

AS3.0 JIT vs. Interpreted

I’ve been developing an application recently that requires large numbers of classes to be initialised as soon as the application is loaded. It’s an isometric display engine, a la “Sim City”, with a world map of 800 x 600 tiles, and multiple layers ( terrain, objects, transport networks etc) there’s potential for over 100,000 instances!!!

I found ActionScript 3.0 and AVM2: Performance Tuning by Gary Grossman, which covers many aspects of how AVM2 is different from AVM1. The part I was interested in was about $init and $cinit (class constructor) functions being interpreted and everything else being JIT.

The initial setup of the engine runs over a timed loop (to stop script timeouts), and this was typically taking 20 to 30 seconds. After reading the above PDF, it became clear that class constructors are interpreted, not JIT compiled, so all I had to do was move the code out of the constructor, into an init() function, and call if after the constructor, this shaved a huge amount of time off the initial build of the landscape.

Some initial tests, with a for loop running from 0 to 10000 showed that in the constructor it took about 350ms, and called via another method, it took only 240ms. It is not always faster, but 90% of the time it’s faster.

Read more

AS3.0 Better Singletons

I’ve found a better more robust way of enforcing singletons in AS3.0

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

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

public function Singleton( pvt:SingletonEnforcer )
{
// init class
}
}
}

internal class SingletonEnforcer{}
[/as]
Note: The class “SingletonEnforcer” is actually placed within the same .as file as the Singleton class, but placed outside the package{} parenthesis, therefore, the class “SingletonEnforcer” can only be accessed from within this .as file, so if the Singleton’s constructor is called from anywhere else, you’ll get an error.

AS3.0 Reversed for loop

Today I came across an easy mistake to make when new to AS3.

I set up a for loop, to count backwards through an Array. But for some strange reason the loop was never terminating! It was simple, here’s the original code

[as]
var i:uint;
for( i=arr.length-1; i>=0; i– )
{
}
[/as]

The mistake was simple, I had set i as a uint, so it could never go below 0, so just had to make i an int. It sounds stupid once you realise it, but it wasted enough of my time!

Looping within a range

Something I have to do very often is looping a number within a range. This could be for a carousel navigation, a rotating banner or image slideshow, etc. The concept is simple, have a range, say 1 – 20, and simply call next() / previous() on it and return the new number, if it goes above 20, return to 1, if below 1, return to 20.
Read more

PolarClock Dashboard Widget

widget.jpg

A lot of people had been asking for this as a widget. So i’ve put together this version for the OS X Dashboard. The options are limited to language selection only.

Download:
[zip] PolarClock OSX Widget 356Kb

Read more

New role at Digit!

After being freelance for the last 8 months, which has been pretty chaotic, I’ve accepted the position of “Senior Creative Technologist” at digit, a long established London agency.

It’s going to be a really interesting role for me, where I’ll carry on working with the Flash Platform (Flash, Flex, and hopefully some AIR apps), but also be involved in developing and designing physical interaction pieces using many technologies that I’ll be new to. Like Java, C#, mobile phone development, touch screens, motion sensors, whatever goes really. It’s going to be a great opportunity to broaden my knowledge.

RSS/Atom syndication made easy

A while ago adobe released their as3syndicationlib for easy access to RSS & Atom feeds by converting either RSS 1.0/2.0 or Atom feeds into generic data accessible via the IFeed interface. These libraries also require adobe’s corelib.

It literally took me 5 minutes to write a simple wrapper class to handle the loading of the feeds, and simply trace out the headlines of each item.
Read more

PolarClock 3.0 Release

launch.jpg

It’s all done!

Re-worked from the ground up in ActionScript 3, this release should be much less CPU intensive, and has had heaps of new features added. Read all about it at it’s new permanent home.

PolarClock Home

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.

Newer Entries Previous Entries