Skip to content

Instantly share code, notes, and snippets.

@lynxerzhang
Created March 29, 2013 09:51
Show Gist options
  • Save lynxerzhang/5269936 to your computer and use it in GitHub Desktop.
Save lynxerzhang/5269936 to your computer and use it in GitHub Desktop.
package
{
import flash.events.Event;
import flash.events.EventPhase;
import flash.events.IEventDispatcher;
/**
* @see once$
* @example
* this.stage.addEventListener(MouseEvent.CLICK, execute$(trace, this, false)(this, "global execute$ method test"));
*
* will output scope's name information and provide parameter "global execute$ method test"
*/
public function execute$(fun:Function, scope:* = null, once:Boolean = false):Function{
return function(...args):Function{
return function(evt:Event):void{
if(scope){
fun.apply(scope, args);
}
else{
if(args.length == 0){
fun();
}
else{
fun.apply(null, args);
}
}
if(once){
IEventDispatcher(evt.currentTarget).removeEventListener(evt.type, arguments.callee, evt.eventPhase == EventPhase.CAPTURING_PHASE);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment