Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FLEX: Programmatically remove Alert?

I need to programmatically remove an alert.

This is why: My application uses BrowserManager to enable deep linking based off of the content in the #hash part of the url. If an alert is currently up, and the user hits the back button, the application will revert back to its previous state. But the Alert will still be up, and in many cases irrelevant at that point.

So is there a way to programmatically remove the Alert? so when the hash fragment changes I can remove it.

Thanks!

like image 851
JD Isaacks Avatar asked Dec 14 '22 05:12

JD Isaacks


2 Answers

It turns out the Alert.show function returns an Alert reference and then just uses PopUpManager to add it to the display list. so if you capture the return reference when you call Alert.show you can tell PopUpManager to remove it. :)

like image 85
JD Isaacks Avatar answered Dec 21 '22 10:12

JD Isaacks


You can do this by keeping the Alert object as member data, and then setting its visible property to false when you're done with it. Next time you need to show an Alert, don't create a new one - grab the one you've already created and set its properties, then set visible to true again.

private var myAlert : Alert;

public void showAlert( message: String, title : String ) : void
{
    hideAlert();

    myAlert = Alert.show( message, title, Alert.OK | Alert.NONMODAL );
}

public void hideAlert() : void
{
    if( myAlert != null && myAlert.visible ) {
        myAlert.visible = false;
    }
}
like image 32
Matt Dillard Avatar answered Dec 21 '22 11:12

Matt Dillard