Using Alert.show in Flex 3
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.det开发者_运维技巧ail == mx.controls.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");
}
}
精彩评论