Created
March 29, 2013 09:51
-
-
Save lynxerzhang/5269936 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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