Activate your free membership today | Log-in

Tuesday, May 6th, 2008

Porting Dojo Methods to Flash

Category: Dojo, 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:

JAVASCRIPT:
  1.  
  2. _global.lang = {
  3.         hitch: function(scope, method){
  4.                 if(!method){
  5.                         method = scope;
  6.                         scope = _global;
  7.                 }
  8.                 var args;
  9.                 if(arguments.length>2){
  10.                         args = arguments;
  11.                         args.shift();
  12.                         args.shift();
  13.                 }
  14.                 if(typeof(method) == "string"){
  15.                         return  function(){ scope[method].apply(scope, args) };
  16.                 }
  17.                 return function(){ method.apply(scope, args) };
  18.         }
  19. }
  20.  

In part two he adds support for dojo.connect(), resulting in:

JAVASCRIPT:
  1.  
  2. _global.lang = {
  3.         __conListeners:{},
  4.         __id:0,
  5.         connect: function(source, event, target, callback){
  6.                 var hitched = this._hitch(target, callback);
  7.  
  8.                 var listener = new Object();
  9.                 listener[event] = function(args){
  10.                         hitched();
  11.                 }
  12.  
  13.                 if(!source.broadcasters) {
  14.                         source.broadcasters = {};
  15.                         AsBroadcaster.initialize(source)
  16.                 }
  17.  
  18.                 source.addListener(listener);
  19.  
  20.                 if(!source.broadcasters[event]){
  21.                         source[event] = function(){
  22.                                 source.broadcastMessage(event, arguments);
  23.                         }
  24.                         source.broadcasters[event] = true;
  25.                 }
  26.  
  27.                 var id = "connect_"+this.__id++;
  28.                 this.__conListeners[id] = {listener:listener, source:source};
  29.                 return id;
  30.         }
  31.  
  32.         disconnect: function(id){
  33.                 var con = this.__conListeners[id];
  34.                 if(con){
  35.                         con.source.removeListener(con.listener);
  36.                         con = null;
  37.                 }
  38.         }
  39. }
  40.  

Posted by Dion Almaer at 7:12 am

++++-
4.5 rating from 14 votes

1 Comment »

Comments feed TrackBack URI

Thanks. Good article.

Comment by videoizle — May 8, 2008

Leave a comment

You must be logged in to post a comment.