Apache flex flex 3:使用警报窗口将值传递给函数

Apache flex flex 3:使用警报窗口将值传递给函数,apache-flex,alert,Apache Flex,Alert,我有一个功能,当用户点击一个按钮时,可以检查一些东西。如果找到了某个对象,则会出现一个警报,表示该对象已被找到,并询问他们是否希望允许这种情况发生,或者撤消导致找到该对象的操作。代码如下所示: Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer); private function conflictAnswer(event:CloseEvent):void { if (event.

我有一个功能,当用户点击一个按钮时,可以检查一些东西。如果找到了某个对象,则会出现一个警报,表示该对象已被找到,并询问他们是否希望允许这种情况发生,或者撤消导致找到该对象的操作。代码如下所示:

Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer);
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)
    {

    }
}
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));
    }
}
按“是”或“否”时,将调用conflictAnswer函数。。。看起来是这样的:

Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer);
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)
    {

    }
}
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(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer);
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)
    {

    }
}
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));
    }
}
但它不起作用

有人能帮我吗

谢谢 BRD

编辑 在阅读了第一个回复后,我想到了以下几点:

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函数如下所示:

Alert.show(thisString1, "Conflict: Multiple Projects", 3, this, conflictAnswer);
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)
    {

    }
}
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()
返回一个警报实例,该实例包含
数据
字段,您可以在其中设置数据:

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

我真的不知道如何利用你的回应来帮助我。我明白你的意思,我只是不知道该怎么做。我有一个警报。显示呼叫。。。我可以在这个范围内设置数据吗?Alert.show显示在原始问题中。我在回答中添加了一行,以澄清我说“Alert.show()返回警报实例”的意思:)我还有几个问题。。。我在下面添加了它们,然后编辑了原始帖子的一部分。我从ConflictResponse中得到了一个NaN | NaN的警告窗口。。。但是如果做一个Alert.show(typeof(answers[0]);在第一部分,我得到一个“数字”的返回。。。有什么想法吗?