Doing Doit
For my Father’s birthday, I made him a Doit Explorer (requires Flash 9, check your version, download the latest). Doit is a Logo program he showed me when I was small child. It’s fascinated me ever since.
Making the explorer was one of my best hackathons ever. Three days: three thousand lines. Clean and delicious ActionScript 3. Stevey’s right that JavaScript is the next big language and ActionScript 3 is its best incarnation. What’s AS3 like? Take Java, add first class functions, make reflection easy, provide ArrayList, HashMap, and XML literals, remove inner classes and mandatory type declarations, jiggle the syntax a bit, and that’s ActionScript 3. In the hands of a Rubyist or a Lambda Knight, AS3 is a formidable foil. For instance, here’s how I define doit’s controls:
new Keymap([this, stage],
{ENTER: toggleDoit, SPACE: clear},
Keymap.zeroIn('RIGHT', 'dr', 1, wrapDegrees),
Keymap.multiplier('UP', 'stepRate', 'dstepRate'),
Keymap.multiplier('W', 'dhue', 'ddhue'),
Keymap.flip('C', 'controlsVisible'),
Keymap.flip('H', 'statusEnabled')
)
// Elsewhere...
function wrapDegrees(v:Number):Number {
return wrap(v, 0, 360)
}
public function wrap(v:Number, min:Number, max:Number):Number {
v %= max - min
if (v < 0) v += max
return v + min
}
A Keymap is initialized by a list of key mappings where each key mapping is just an association of key names and functions. Utility functions such as Keymap.flip generate key mappings:
{C: function() { controlsVisible = !controlsVisible }}
How do I do it? Through AS3’s potent and direct reflection:
public static function flip(key:String, prop:String):Object {
var map:Object = {}
map[key] = function():void {
this[prop] = !this[prop]
}
return map
}
Certainly there are limitations and AS3 has noteworthy limitations; however, if your goal is to make a graphical, web deployable application, any technology choice besides Flash should be explained and justified. (I’ll grant anyone that Flash’s out-of-box text handling needs some work.)




§Commentary