class cs.utils.Scope{ public static function rewire(scope:Object, func:Function):Function { var args:Array = []; if (arguments.length > 2) { args = arguments.splice(2, arguments.length - 2); } return function() { return func.apply(scope, args.concat(arguments)); } }}
import cs.utils.Scope; var xml:XML = new XML();xml.ignoreWhite = true;xml.onLoad = Scope.rewire(this, xmlLoadHandler, "Hello!", xml); xml.load("file.xml"); function xmlLoadHandler(word:String, xmlFile:XML, success:Boolean):Void{ if (!success) { // D'oh! } else { trace(this); // _level0 trace(word); // output: Hello! trace(xmlFile == xml); // output: true trace(this == xml); // output: false }}