在 Flex 3 中使用 Alert.show

发布于 2024-09-09 05:22:16 字数 463 浏览 3 评论 0原文

在 Flex 3 中,当我使用时,

Alert.show("some text");

我会收到一条警报消息以及“确定”按钮。当我按下“确定”按钮时,我收到另一条警报消息。我已经尝试过以下代码,但它不起作用。

Alert.show(" Simulation for " + id_formulator.nme + " Campaign", null, mx.controls.Alert.OK, this, alertListener, null, mx.controls.Alert.OK);

private function alertListener(eventObj:Event):void {
    if (eventObj.detail == mx.controls.Alert.OK) {
        Alert.show("next message");
    }
}

In Flex 3, when I use

Alert.show("some text");

I will get an alert message along with the OK button. When I press the OK button I get another alert message. I have tried the following code, but it's not working.

Alert.show(" Simulation for " + id_formulator.nme + " Campaign", null, mx.controls.Alert.OK, this, alertListener, null, mx.controls.Alert.OK);

private function alertListener(eventObj:Event):void {
    if (eventObj.detail == mx.controls.Alert.OK) {
        Alert.show("next message");
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不知所踪 2024-09-16 05:22:16

问题是在您的函数alertListener 中,您将参数eventObj 声明为Event 类型。 Event 类没有详细信息字段。然而,CloseEvent 子类却可以。它也恰好是由关闭警报调度的事件类型。

此外,您只能在 this 关键字具有作用域的上下文中使用它。因此,您需要将其包装在初始化函数中(而不仅仅是静态代码中的浮动)。您需要将 initialize="showAlerts()" 添加到窗口,以便在否则,只需替换为您选择的事件

此外,我建议使用 import 指令,因为它使您的代码明显更短,并且短代码更易于维护,

因此您的代码应该是:

import mx.controls.Alert;
import mx.events.CloseEvent;

private function showAlerts():void {
    Alert.show("Simulation for " + id_formulator.nme + " Campaign", null, Alert.OK, this, alertListener, null, Alert.OK);
}

private function alertListener(eventObj:CloseEvent):void {
    if (eventObj.detail == Alert.OK) {
        Alert.show("next message");
    }
}

The problem is that in your function alertListener, you declared the parameter eventObj to be of type Event. The Event class doesn't have a detail field. However, the CloseEvent subclass does. It also happens to be the type of the event dispatched by an Alert being closed.

Also, you can only use the this keyword in a context where it has scope. So you need to wrap it inside an initialize function (rather than just float in static code. You'll need to add initialize="showAlerts()" to the window in order for it to happen when the window is opened. Otherwise, just replace with your event of choice

Additionally, I would suggest using the import directive, since it makes your code significantly shorter, and short code is easier to maintain.

So your code should be:

import mx.controls.Alert;
import mx.events.CloseEvent;

private function showAlerts():void {
    Alert.show("Simulation for " + id_formulator.nme + " Campaign", null, Alert.OK, this, alertListener, null, Alert.OK);
}

private function alertListener(eventObj:CloseEvent):void {
    if (eventObj.detail == Alert.OK) {
        Alert.show("next message");
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文