gpt4 book ai didi

apache-flex - 弹性 3 : passing values to function using alert window

转载 作者:行者123 更新时间:2023-12-04 06:26:34 25 4
gpt4 key购买 nike

我有一个函数可以在用户单击按钮时检查某些内容。如果找到了某个东西,则会出现一个警报,说明它已被找到,并询问他们是否愿意允许这种情况发生,或者撤消导致该东西被找到的操作。代码如下所示:

Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer);

按"is"或“否”后,将调用冲突答案函数......它看起来像这样:
private function conflictAnswer(event:CloseEvent):void
{
if (event.detail == Alert.YES)
{
Alert.show(
}
}

我的问题是,我将如何传递显示警报的函数中保存的一些变量?我试过这样的事情:
Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer(Event, var1, var2));


private function conflictAnswer(event:CloseEvent, varA, varB):void
{
if (event.detail == Alert.YES)
{

}
}

但它没有用。

有人可以帮我吗?

谢谢
sibling

编辑
阅读第一个回复后,我想出了这个:
answers[0] = cPositions[i][0];
answers[1] = cPositions[i][1];
var anAlert:Alert = Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer);
anAlert.data = {answers:Array};

然后 conflictAnswer 函数如下所示:
private function conflictAnswer(event:CloseEvent):void
{
var projectID:Number = event.currentTarget.answers[0];
var positionID:Number = event.currentTarget.answers[1];
if (event.detail == Alert.YES)
{
Alert.show(String(projectID + " | " + positionID));
}
}

但这不起作用......有什么想法吗?

最佳答案

Alert.show()返回一个具有 data 的警报实例您可以在其中设置数据的字段:

var anAlert:Alert = Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer);
anAlert.data = {var1:var1, var2:var2};

然后在事件处理程序中,您可以获得数据对象:
var myData:Object = event.currentTarget.data;
var var1:Object = myData.var1;
var var2:Object = myData.var2;

对于您的代码,它将如下所示:
answers[0] = cPositions[i][0];
answers[1] = cPositions[i][1];
var anAlert:Alert = Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer);
anAlert.data = {answers:answers};

进而:
private function conflictAnswer(event:CloseEvent):void
{
var projectID:Number = event.currentTarget.data.answers[0];
var positionID:Number = event.currentTarget.data.answers[1];
if (event.detail == Alert.YES)
{
Alert.show(String(projectID + " | " + positionID));
}
}

关于apache-flex - 弹性 3 : passing values to function using alert window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5983021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com