4 Replies Latest reply on Aug 25, 2006 11:49 AM by ntsiii

    Confirm Dialog?

    Josh Johnson Level 1
      As a flex newbie with a pretty good understanding of Javascript, I was thrilled to find the Alert.show() function available to replace the alert() function I often used in Javascript. That got me wondering... is there a corresponding function for the confirm() function as well? I tried Confirm.show(), but with no luck, as that shows up as an undefined property.

      I was hoping there's a simple way to activate modal confirmation dialogs, as I'd hate to have to build an entire component just for that.

      Thanks,
      Josh
        • 1. Re: Confirm Dialog?
          ntsiii Level 3
          You can control the buttons displayed by Alert.

          Remember that Alert is not truly modal. It will NOT stop execution of code that follows the call to Alert.show().

          You MUST use an event handler function to process the response from an Alert.

          There is NO WAY to block execution of code in the Flash Player.

          Got it?

          Tracy
          • 2. Re: Confirm Dialog?
            Josh Johnson Level 1
            So if I understand what you're saying, I can use the Alert.show() function to invoke a dialog that uses more than one button instead of the standard OK button, but I'll have to create an event handler to capture and process which button is pressed. Correct?

            Is there a good place to look for documentation on the Alert function, or better yet example code for doing things like a confirm dialog?
            • 3. Re: Confirm Dialog?
              stalkert
              Well, there is an relative simply solution for this:

              Make a button with calls a function when clicking:
              <mx:Button label="Click Me" click="clickHandler(event);"/>

              Use the following implementation of the eventhandler:

              <mx:Script>
              <![CDATA[

              import mx.controls.Alert;
              import mx.events.CloseEvent;

              // Event handler function uses a static method to show
              // a pop-up window with the title, message, and requested buttons.
              private function clickHandler(event:Event):void {
              Alert.show("Do you want to save your changes?", "Save Changes", 3, this, alertClickHandler);
              }

              // Event handler function for displaying the selected Alert button.
              private function alertClickHandler(event:CloseEvent):void {
              if (event.detail==Alert.YES)
              status.text="You answered Yes";
              else
              status.text="You answered No";
              }

              ]]>
              </mx:Script>
              • 4. Re: Confirm Dialog?
                ntsiii Level 3
                Yep, that's all there is to it.

                The third parameter of the show method is a bitmask that controls the displayed buttons.

                Tracy