Flex带参数的事件处理方法

flex事件的处理方法默认都带有一个参数,就是Event,如果我们在添加监听或者其它事件处理方法中想传递自己定义的参数时,应该怎么处理?
下面给大家举一个很简单的例子,
<?xml version="1.0" encoding="utf-8"?>
<s:Application minHeight="600"
minWidth="955"
creationComplete="application1_creationCompleteHandler(event)"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.controls.Button;
import mx.events.FlexEvent;

protected function application1_creationCompleteHandler(event:FlexEvent):void
{
for (var i:int = 0; i < 5; i++)
{
var b:Button = new Button();
b.label = 'button' + i;
b.addEventListener(MouseEvent.CLICK, [color=red]ffHandler('' + i)[/color]);
addElement(b);
}
}


private function ffHandler(string:String):Function
{
[color=red]return function(e:MouseEvent):void
{
clickHandler.apply(null, [e, string])
};[/color] }

private function clickHandler(e:Event, ... args):void
{
tt.text = args[0].toString();
}
]]>
</fx:Script>

<s:Label id="tt"/>
</s:Application>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值