Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex Flex:将参数发送到警报closeHandler_Apache Flex_Parameters_Alert_Send - Fatal编程技术网

Apache flex Flex:将参数发送到警报closeHandler

Apache flex Flex:将参数发送到警报closeHandler,apache-flex,parameters,alert,send,Apache Flex,Parameters,Alert,Send,是否可以向closeHandler警报函数发送参数? 函数获取的第一个参数是CloseEvent,但是如何发送另一个参数呢 <s:Button id="btnLoadLocalData" label="Load data" click="Alert.show('Populate list with local data?', '', Alert.YES | Alert.CANCEL, this, loadLocalData(???parameters???), null

是否可以向closeHandler警报函数发送参数? 函数获取的第一个参数是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);"/>


谢谢大家!

这应该可以使用Flex的动态函数构造。有人提出了类似的问题

下面是一个例子:

<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);
}
参数和处理程序:

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));}
}
<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);"/>
您的组件:

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));}
}
<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);"/>

一种方法可能是在警报创建范围内创建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);
}

函数btnLoadLocalData\u clickHandler(事件:事件):无效{
var someVar:Object=someCalculation();
var closeHandler:Function=Function(closeEvent:closeEvent):void{
//这里有someVar
};
Alert.show('用本地数据填充列表?','',Alert.YES | Alert.CANCEL,this,closeHandler,null,Alert.OK);
}

我处理此用例的典型方法是将数据添加到警报表单中。比如说

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;
然后在警报的关闭处理程序中

private function OnAlertResult(event:CloseEvent):void {
    trace(event.target.data);
}

我通常使用匿名函数包装带有参数的函数调用:

Alert.show("Are you sure?", Alert.YES | Alert.CANCEL, null, function(event:CloseEvent):void{doSomething(event.detail, param1, param2);}, null, Alert.CANCEL)

正是我需要的!我希望尽可能减少处理程序函数的数量。非常感谢。非常棒的闭包和作用域的使用很好地实现了一个非常需要的技巧