Skip to content

Instantly share code, notes, and snippets.

@goodbar
Created March 11, 2011 09:22
Show Gist options
  • Save goodbar/865663 to your computer and use it in GitHub Desktop.
Save goodbar/865663 to your computer and use it in GitHub Desktop.
an ActionScript function that uses the 'newactivation' opcode.
public static function create(target:Object, handlerFunction:Function, shouldAppend:Boolean = true, ... args) : Function
{
var oTarget:Object;
var oFunction:Function;
var oAppend:Boolean = true;
var oArgs:Array;
var f:Function;
var oParams:Array;
var i:int;
var d:Dictionary;
var loc1:*;
oTarget = target;
oFunction = handlerFunction;
oAppend = shouldAppend;
f = check(oTarget, oFunction, oAppend, oArgs); //check() returns null if conditions not satisfied
if(f != null) {
return f;
}
oParams = new Array();
while((i = 0) < oArgs.length) {
oParams.push(oArgs[i++]);
}
d = new Dictionary(true);
d["oTarget"] = oTarget;
d["oParams"] = oParams;
d["oFunction"] = oFunction;
d["appendParams"] = oAppend;
d["dFunction"] = function():* {
/* Apperantly arguments.callee refers to d["dFunction"] and callee.delegate refers to 'd'? */
var loc1:* = arguments.callee.delegate;
return loc1["oFunction"].apply(loc1["oTarget"], loc1["appendParams"] ? (arguments.concat(loc1["oParams"])) : (loc1["oParams"]));
}
d["dFunction"].delegate = d;
delegates.push(d); //delegates is a field variable -- class variable
return d["dFunction"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment