Tuesday, May 6th, 2008
Porting Dojo Methods to Flash
Mike Wilcox has started a nice series of posts on porting Dojo methods to Flash as a homage for Open Screen (aside: I applaud Adobe's intentions, but need to see a non-assert of their IP before I can do anything with it.)
In part one of the series Mike ports dojo.hitch to ActionScript:
-
-
_global.lang = {
-
hitch: function(scope, method){
-
if(!method){
-
method = scope;
-
scope = _global;
-
}
-
var args;
-
if(arguments.length>2){
-
args = arguments;
-
args.shift();
-
args.shift();
-
}
-
if(typeof(method) == "string"){
-
return function(){ scope[method].apply(scope, args) };
-
}
-
return function(){ method.apply(scope, args) };
-
}
-
}
-
In part two he adds support for dojo.connect(), resulting in:
-
-
_global.lang = {
-
__conListeners:{},
-
__id:0,
-
connect: function(source, event, target, callback){
-
var hitched = this._hitch(target, callback);
-
-
var listener = new Object();
-
listener[event] = function(args){
-
hitched();
-
}
-
-
if(!source.broadcasters) {
-
source.broadcasters = {};
-
AsBroadcaster.initialize(source)
-
}
-
-
source.addListener(listener);
-
-
if(!source.broadcasters[event]){
-
source[event] = function(){
-
source.broadcastMessage(event, arguments);
-
}
-
source.broadcasters[event] = true;
-
}
-
-
var id = "connect_"+this.__id++;
-
this.__conListeners[id] = {listener:listener, source:source};
-
return id;
-
}
-
-
disconnect: function(id){
-
var con = this.__conListeners[id];
-
if(con){
-
con.source.removeListener(con.listener);
-
con = null;
-
}
-
}
-
}
-












Thanks. Good article.