5 Replies Latest reply on Feb 3, 2009 3:58 PM by -Hob

    True Modal Popup?

      Hi,
      I am very frustrated with the PopupManger way of creating popup boxes. It seems as though there is no way to make a simple popup that is truly modal that you can retrieve values from once it has been removed from the screen. In all of the examples I have seen you either have to do whatever you want to do with the data you are gathering in the popup from the popup itself (i.e. do something like parentApplication.whatever) or use a close listener. with both methods you pretty much have to do a custom popup or listener for every action you want to do. I just want a popup that has a text area and an ok and cancel button that I can use all over my code. For and example of what I mean (this does not work because PopupManager creates a static object):


        • 1. Re: True Modal Popup?
          -Hob
          The problem is that Flex is not multi-threaded, so you can't have your function block until the modal is closed. Flex is an event driven system though, so what your trying to do isn't very hard. All you need to do is dispatch an "ok" event when the ok button is closed, then listen for it wherever you create the pop-up. Whenever you dispatch it, you know its kosher to grab the value of the txtName field in the pop-up. You don't even need the popup.canceled() method, since you know that ok was pushed due to the type of event you're listening for.
          1 person found this helpful
          • 2. Re: True Modal Popup?
            Thanks for the response Hob,
            You have confirmed there is no really good solution. Even in the method you describe you have to have some sort of switch or custom 'something' for every place you need the use the component. Would be really nice if you could just call it and get the data from it all from the same method.
            • 3. Re: True Modal Popup?
              -Hob Level 1
              I guess I'm just used to the event-based environment in Flex at this point. I really like just having event listeners.
              1 person found this helpful
              • 4. Re: True Modal Popup?
                john isaacks Level 1
                For example add this to the click property of the OK button:

                click="{PopUpManager.removePopUp(this); dispatchEvent(new Event('OK')}"

                and listen for it like this:

                var popup:NodeName = new NodeName();
                popup.addEventListener('OK', onOK);
                PopUpManager.addPopUp(popup, this, true);
                PopUpManager.centerPopUp(popup);


                private function onOK (e:Event):void
                {
                trace("the name chosen is: "+popup.nodeName);
                //do whatever with the value...
                }



                Note: I have not tested this. Also a better way might be to right your own custom event class and pass the text you want in the event like this:

                click="{PopUpManager.removePopUp(this); dispatchEvent(new CustomEvent(CustomeEvent.EVENT_TYPE, this.nodeName)}"


                and listen for it like this:

                popup.addEventListener(CustomeEvent.EVENT_TYPE, onOK);

                private function onOK (e:CustomeEvent):void
                {
                trace("the name chosen is: "+e.text);
                //do whatever with the value...
                }
                • 5. Re: True Modal Popup?
                  -Hob Level 1
                  You've got it. I highly recommend storing your event types as constants. Will save you debugging headaches later on due to typos.
                  1 person found this helpful