Dinesh
Dinesh

Reputation: 2066

How to avoid the display of multiple alert windows in Flex

I have a timer in my application. For every 30 min, it will hit the web services and fetch the data and updates the UI. The application was working fine till yesterday. Suddenly, because of some issue, the web services were not available for some time. During that period, Application displayed the RPC Error multiple times(More than 100 alert boxes) in alert window. Because of this alert boxes, my application was hanged and i was not able to do anything.

I have tried several approaches, but nothing worked.Finally, I have tried to use a flag. In all the approaches, this looked promising. so i have implemented it.Basically, in this approach whenever we open an alert we will set a flag.While opening and closing alert we will reset this flag. But it didn't work as expected. Is there any approach, which can help us in avoiding multiple alert windows.

Please help me, to fix this issue.

Upvotes: 0

Views: 1028

Answers (1)

alxx
alxx

Reputation: 9897

I would write wrapper for opening alerts, and use only this wrapper, not Alert.show in the code:

public class AlertWrapper {

   private static var lastAlert:Alert;

   public static function showAlert(text:String, title:String):void {
       if (lastAlert) {
            PopUpManager.removePopUp(lastAlert);
            //or
            //return; //ignore last alert
       }
       lastAlert = Alert.show(text, title, null, 4, onAlertClose);
   }

   private static function onAlertClose(event:CloseEvent):void {
       lastAlert = null;
   }
}

Imports are missing, but I hope the idea is clear.

Upvotes: 2

Related Questions