Back from Flash on the Beach

photo by BIT-101
I got back from Brighton yesterday, exhausted after 3 days of excellent sessions and some heavy drinking sessions too!

The high points for me were Mario Klingemann’s “2D or not 2D, that is the question” talk about working with BitmapData. He showed how to make a “Magic Wand” tool a la photoshop. His process was impressive to say the least, and I’m very interested in playing with the paletteMap method of the BitmapData class.

The session from André Michelle was amazing, he demoed his PopForge sound synthesis engine. Generating sound entirely within flash at run-time. See the video below, this is all generated and manipulated in flash. It’s simply amazing, I can’t wait to get some time (after this post) to start messing around with sound in flash.

Read more…

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

	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{}

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

var i:uint;
for( i=arr.length-1; i>=0; i– )

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…

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…