How to capture Alert Dialog Box Selection?
Within an event开发者_JAVA技巧 handler I have an Alert.show(...) that prompts a user for confirmation. How can I capture the selection of the alert prompt and use it within the event handler. For example:
private function mainEvtHandler(event:DynamicEvent):void {
 var alert:Alert = Alert.show("Are you sure?", "Confirmation", Alert.YES|Alert.NO, this, alertHandler);
 // How can I retrieve the selection and use it within this event handler?
 // i.e. if (alert == Alert.Yes) { ...
 var index:int = arrayColl.getItemIndex(event.data)
 ...
 ...
You can declare the alertHandler as nested function ...
private function mainEvtHandler(event:DynamicEvent):void {
  var alertResult: int = -1;
  function alertHandler(evt:CloseEvent):void {
     alertResult = evt.detail;
  }
  var alert:Alert = Alert.show("Are you sure?", "Confirmation", Alert.YES|Alert.NO, this, alertHandler);
  if (alertResult == Alert.Yes) {
     var index:int = arrayColl.getItemIndex(event.data);
  ...
}
... or you can use an anonymous function
private function mainEvtHandler(event:DynamicEvent):void {
  Alert.show("Are you sure?", "Confirmation", Alert.YES|Alert.NO, this, 
      function (nestedCloseEvent:CloseEvent):void {
         if (nestedCloseEvent.detail == Alert.Yes) {
            var index:int = arrayColl.getItemIndex(event.data);
            ...
         }
      }
  );
}
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论