Как захватить выбор диалогового окна Alert? - PullRequest
1 голос
/ 05 октября 2010

В обработчике событий у меня есть Alert.show(...), который запрашивает у пользователя подтверждение.Как я могу зафиксировать выбор предупреждения и использовать его в обработчике событий.Например:

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)
 ...
 ...

1 Ответ

1 голос
/ 05 октября 2010

Вы можете объявить alertHandler как вложенную функцию ...

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

}

... или использовать анонимную функцию

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);
            ...
         }
      }
  );
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...