cil*_*ili 9 apache-flex parameters alert send
是否可以将参数发送到closeHandler Alert功能?函数获取的fisrt参数是CloseEvent,但如何发送另一个?
<s:Button id="btnLoadLocalData" label="Load data"
click="Alert.show('Populate list with local data?', '', Alert.YES | Alert.CANCEL, this, loadLocalData(???parameters???), null, Alert.OK);"/>
Run Code Online (Sandbox Code Playgroud)
谢谢!
Chr*_*man 13
一种方法可能是在警报创建的范围内创建closeHandler.
这是一个例子:
<s:Button id="btnLoadLocalData" label="Load data" click="btnLoadLocalData_clickHandler(event)"/>
function btnLoadLocalData_clickHandler(event:Event):void {
var someVar:Object = someCalculation();
var closeHandler:Function = function(closeEvent:CloseEvent):void {
// someVar is available here
};
Alert.show('Populate list with local data?', '', Alert.YES | Alert.CANCEL, this, closeHandler, null, Alert.OK);
}
Run Code Online (Sandbox Code Playgroud)
Jas*_*wne 11
这应该可以使用Flex的动态功能构造.这里也提出了类似的问题.
这是一个例子:
参数和处理程序:
var parameters:String = "Some parameter I want to pass";
private function loadLocalData(e:Event, parameter:String):void
{
// voila, here's your parameter
}
private function addArguments(method:Function, additionalArguments:Array):Function
{
return function(event:Event):void {method.apply(null, [event].concat(additionalArguments));}
}
Run Code Online (Sandbox Code Playgroud)
你的组件:
<s:Button id="btnLoadLocalData" label="Load data"
click="Alert.show('Populate list with local data?', '', Alert.YES | Alert.CANCEL, this, addArguments(loadLocalData, [parameters])), null, Alert.OK);"/>
Run Code Online (Sandbox Code Playgroud)
小智 10
处理此用例的典型方法是将数据添加到Alert表单中.例如
var o:Object = new Object();
o["stuff"] = "quick brown fox";
var alert:Alert = Alert.show("Message", "Title", mx.controls.Alert.YES | mx.controls.Alert.NO, null, OnAlertResult);
alert.data = o;
Run Code Online (Sandbox Code Playgroud)
然后在Alert的关闭处理程序中
private function OnAlertResult(event:CloseEvent):void {
trace(event.target.data);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6704 次 |
| 最近记录: |