views:

780

answers:

3

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!

A: 

I don't think that is possible.

You can create your own alert component subclassing TitleWindow and then use PopupManager to show/hide them.

Chetan Sastry
Actually it is possible...I answered it below and explained how..I already tested it out and it works. Thanks.
John Isaacks
+2  A: 

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

John Isaacks
+1  A: 

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;
    }
}
Matt Dillard