addEventListener注册事件进行传递参数的方法(AS3)
2012-02-06 12:11:53 来源:本站整理核心提示:addEventListener注册事件进行传递参数的方法(AS3):/** * @author:ycccc8202 * @用途:注册事件进行传递参数的代理类 * @date:2007.8.26 * @example: * import CYPL.utils.JEventDelegate stage.add
addEventListener注册事件进行传递参数的方法(AS3):
- /**
- * @author:ycccc8202
- * @用途:注册事件进行传递参数的代理类
- * @date:2007.8.26
- * @example:
- * import CYPL.utils.JEventDelegate
- stage.addEventListener(MouseEvent.MOUSE_DOWN,
- JEventDelegate.create(mouseDownHandler,"a","b"));
- function mouseDownHandler(e:MouseEvent,...arg) {
- trace(e)
- trace(arg)
- }
- */
- package CYPL.utils{
- import flash.events.Event
- public class JEventDelegate {
- public function JEventDelegate() {
- }
- public static function create(f:Function,... arg):Function {
- return function(e:Event){
- f.apply(null,[e].concat(arg));}
- };
- public static function toString():String {
- return "Class JEventDelegate";
- }
- }
- }
使用格式如下:
- import CYPL.utils.JEventDelegate
- stage.addEventListener(MouseEvent.MOUSE_DOWN,JEventDelegate.create
- (mouseDownHandler,"a","b"));
- function mouseDownHandler(e:MouseEvent,...arg) {
- trace(e)
- trace(arg)
- }
Tags:addEventListener 注册 事件
编辑录入:coldstar [复制链接] [打 印]赞助商链接