在 Flex 3 中使用 Alert.show
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是在您的函数alertListener 中,您将参数eventObj 声明为Event 类型。 Event 类没有详细信息字段。然而,CloseEvent 子类却可以。它也恰好是由关闭警报调度的事件类型。
此外,您只能在 this 关键字具有作用域的上下文中使用它。因此,您需要将其包装在初始化函数中(而不仅仅是静态代码中的浮动)。您需要将
initialize="showAlerts()"
添加到窗口,以便在否则,只需替换为您选择的事件此外,我建议使用 import 指令,因为它使您的代码明显更短,并且短代码更易于维护,
因此您的代码应该是:
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 choiceAdditionally, 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: