FLEX 绑定事件中多参数传递

flex 在事件中添加自己的参数的方法:

var parentItem:XML;

var service1:HTTPService=new HTTPService();

..................此处省略

service1.addEventListener(ResultEvent.RESULT, function (e:ResultEvent):void{onGetChildTables(e,parentItem)}); //这里item就是自己定义的参数,

....................此处省略

这样在ResultEvent函数中就可以使用传入的参数了。

private function onGetChildTables(evt:ResultEvent,parentItem:XML):void{  //添加Tree控件的子节点
    var xml : XML = evt.result as XML;
    var itemList:XMLListCollection=new XMLListCollection(xml.Item);
    if(itemList.length>0){
        delete parentItem.children()[0]; //删除占位子节点
        for each(var item : XML in itemList){
            parentItem.appendChild(item); //添加实际的子节点
        }
    }
}

=============================================

监听在开发中使用的很多,但是addEventListener函数除了加事件类型和调用函数外,能不能加额外的参数呢?

其实是可以的,只要把所加的函数改为新定义的函数,在定义的函数中加入参数即可,示例:

private function handle(e:MouseEvent,str:String): void

{
       Alert.show(str);
}
private function methodWhereyouDostuffAndRegisterListener(): void

{
    var helloStr:String = "hello world!";
    ABCButton.addEventListener(MouseEvent.CLICK,function (e:MouseEvent):void {handle(e,helloStr);});
}

原文地址:https://www.cnblogs.com/zcy_soft/p/1976790.html