Flex Chronicles #5: Alert Drama

There’s a known issue with Alert’s in Flex, using the application level alert, or Alert.show. When you do:

function initApp()
{
        ref = Alert.show("test",
              "",
              Alert.OK,
              this,
              Delegate.create(this, onAlertClose),
              null,
              Alert.OK);
}

function onAlertClose()
{
        ref.deletePopUp();
}

The Alert’s background will stay around. In my investigations, he’s an mc in a very low negative depth. Removing him forcely messed up my app. Matt Chotin then recommended using a doLater. Upon doing so, it fixed my problem. I guess the invalidation routines co-chillin’ deep in the depths of UIObject remove the rect. ::shrugs::

At any rate, if you do this instead:

function onAlertClose()
{
        doLater(this, "killPopup");
}

function killPopup()
{
        ref.deletePopUp();
}

It works good.

Took me 3 days to work through that mess; here’s to you not having to do so.

3 Replies to “Flex Chronicles #5: Alert Drama”

  1. Thanks for writing these. I feel like I’m in the trenches w/ you as I’ve recently dove into the the sea of Flex development.

    What is the benefit of using that type of alert vs using alert(‘My message’, ‘my title’);

  2. The application level ‘alert’ function does 2 things differently than the static ‘show’ function of the ‘Alert’ class:

    – first, and most important, it returns 0 upon success, some other number if it did not. This means that the only way to dismiss the alert is by user interaction. I need to have the option of dismissing the alerts via code, hence me using the Alert.show, which returns a reference to the alert created vs. an error code.
    – secondly, it removes the parent parameter, and swaps the icon and defaultButton parameter locations to be in a more programmer-friendly order

Comments are closed.