as3.0向addEventListener 后面参数传值

方法一:

function EventUp (f:Function,... arg):Function

{
        return function(e:Event){f.apply(null,[e].concat(arg))};
}



例子:
init ();
function init()
{
        var tt:Object=new Object;//要传递的参数
        tt.stb=100;//要传递的参数
        var ss:int=1;//要传递的参数
        
        var traceTime:Timer=new Timer(20,1);
        traceTime.addEventListener (TimerEvent.TIMER,EventUp(traceBespeak,tt,ss,1,1));
        traceTime.start ();
}

function traceBespeak (e:TimerEvent,...arg)
{
        trace (arg[0].stb);
        trace (arg[1]);
        trace (arg);
}
function EventUp (f:Function,... arg):Function
{
        return function(e:Event){f.apply(null,[e].concat(arg))};

}



方法二:

var sayHello:String = "欢迎光临www.FlashJ.cn -Flash,Ria技术博客";
btn1.addEventListener(MouseEvent.CLICK,function (e:MouseEvent){clickHandlerWithArg(e,sayHello)});
function clickHandlerWithArg(e:MouseEvent,arg:String):void
{
var out:String= e.target + "发出事件(有参数) :" + arg;
trace(out);
}

你可能感兴趣的:(as3.0向addEventListener 后面参数传值)