11 Replies Latest reply on Feb 10, 2009 11:51 PM by Richard_Abbott

    How can I create a blocking modal Alert box?

    smokeranch
      Are Alert message boxes always displayed asynchronously? Consider the following code:

      mx.controls.Alert.show("Alert 1", "Alert 1", Alert.OK, this);
      mx.controls.Alert.show("Alert 2", "Alert 2", Alert.OK, this);
      mx.controls.Alert.show("Alert 3", "Alert 3", Alert.OK, this);

      If I put this code in the click event of a button, when I click the button I will see the "Alert 3" box first, and underneath it is Alert 2, and Alert 1 underneath that. Is there any way to display a modal Alert box that "blocks" until the user has dismissed it? Thanks for any suggestions.
        • 1. Re: How can I create a blocking modal Alert box?
          peterent Level 2
          That's the way it is - you can add a callback handler to the Alert.show() function which will be called when the Alert's button is clicked. You can then have that function show the next Alert and so on.
          • 2. Re: How can I create a blocking modal Alert box?
            cicero111
            Is there really no way to wait the answer of an alert message? This would be very strange, because often you need to wait on the reply of a posted message like "Do you really want to to this?" I don't want to jump in an event handler, because the current code execution is broken.

            Look at this:

            some code above
            alert.show("Do you want to do this"?)
            some code below.

            How can I achieve, that the code below have not to be situated in an event handler, which would break execution of the current code. I want to wait until the user presses an alert button before resuming the code below.

            In .NET (and surely in other languages) you can code like:

            answer = messageBox("Do you really want to do this?)
            if (answer = yes) do something.

            Is this possible in flex? How?
            • 3. Re: How can I create a blocking modal Alert box?
              peterent2 Adobe Employee
              Sorry, Flex is entirely event driven, you need to have an event handler. Once you post the dialog box your code should not execute anything the depends on the user's answer. Normally a function which posts an Alert just exits and gives control back to the Flex framework.

              Because of the Flex framework architecture, if you do not give control back to the Flex framework after you do the Alert.show(), the Alert will not be seen. All Alert.show() does it put things into the queue for the Flash player to display. Once control is returned to the Flex framework, the Flash Player then processes the instructions in its queue and the Alert is displayed.

              Given your example, you need to rewrite it like this:

              some code above
              Alert.show("Do you really want to do this?", eventHandler);
              ...
              private function eventHandler( event:CloseEvent ) : void
              {
              if( event.detail == Alert.YES ) {
              do it
              }
              }
              • 4. Re: How can I create a blocking modal Alert box?
                cicero111 Level 1
                Thank you for your quick reply. I feared that this behaviour would be so. Perhaps something for a next release ...
                Thanks.
                • 5. Re: How can I create a blocking modal Alert box?
                  Level 7

                  "Jochen Riegg" <webforumsuser@macromedia.com> wrote in message
                  news:gmqc0d$ot0$1@forums.macromedia.com...
                  > Thank you for your quick reply. I feared that this behaviour would be so.
                  > Perhaps something for a next release ...

                  It seems to me that when the Flex engineers decide what they're going to
                  invest in, they tend to not "fix" things that are only problems to the
                  inexperienced.


                  • 6. Re: How can I create a blocking modal Alert box?
                    cicero111 Level 1
                    Dear Amy,

                    I think for such a simple use case its very inconvenient to chain event handlers.

                    I bet a bottle of champagne that this function will get implemented one day.

                    By the way, I'm very impressed from flex, I programmed a lot with ASP.NET and JSF and I think flex is the first technology which merits the word RIA.
                    • 7. Re: How can I create a blocking modal Alert box?
                      peterent Level 2
                      I think you will lose that bet, I'm afraid. The Flash Player is an event-driven, asynchronous system. It cannot sit and wait for a user to take action. This is not a flaw to be fixed - it is intentionally designed this way to provide maximum display performance while still providing interactivity.

                      You are always inexperienced whenever you learn a new system. If you need to post a number of Alerts as part of your application, consider using an alternate notification as users will probably find the Alerts to be more annoying than useful in the long run. For instance, designate an area of your app for messages. Display notifications there and use different colors to signify importance.

                      If your Alerts are just for significant error conditions, then write a new class to handle the event callback from the Alert and make it easier to write your app.

                      Hope these suggestions help clarify things from our end.
                      • 8. Re: How can I create a blocking modal Alert box?
                        Level 7

                        "Jochen Riegg" <webforumsuser@macromedia.com> wrote in message
                        news:gmrt2e$msc$1@forums.macromedia.com...
                        > Dear Amy,
                        >
                        > I think for such a simple use case its very inconvenient to chain event
                        > handlers.
                        >
                        > I bet a bottle of champagne that this function will get implemented one
                        > day.
                        >
                        > By the way, I'm very impressed from flex, I programmed a lot with ASP.NET
                        > and
                        > JSF and I think flex is the first technology which merits the word RIA.

                        And I really prefer La Crema Chardonnay to Champagne. Want my shipping
                        details?

                        :-D


                        • 9. Re: How can I create a blocking modal Alert box?
                          cicero111 Level 1
                          In deed, this is my first approach to flex, while I' m converting a JSF application to flex. And in deed, the JSF app uses both techniques when notifying to the user: There is a message area, which is turned visible with red text to give error hints as you suggested. But there is also the second technique with Javascript confirm command which halts the application till the user says yes or no i.e. before he deletes some important data in database. This may be annoying, but it was a feature request from our customer.

                          So, don't let us struggle. I learned that halting the application wouldn't meet your architectal needs. And I just said that in this simple use case its unpractical not impossible.

                          So before shipping the champagne let me wait the next two releases. The hope dies at last. For now I send you both lovely greetings and thank your for your suggestions. You helped me very quick. Hope this remains. Thank you.

                          • 10. Re: How can I create a blocking modal Alert box?
                            ntsiii Level 3
                            Resistance is futile.
                            • 11. Re: How can I create a blocking modal Alert box?
                              Richard_Abbott Level 3
                              In passing, and aware that this isn't really the focus of this thread, one of the really useful features of the fact that the Alert box behaves the way it does is that you don't end up with a hung web page for which the only remedy is Task Manager on the browser (or Java VM). Yes, this non-blocking behaviour caught me out a few times at first, but I have come to appreciate it as on balance a better solution.
                              Richard