2 Replies Latest reply on Jun 24, 2010 9:54 AM by rtalton

    Event handler for a popup

    SiHoop Level 1

      The following code opens a popup window. It is closed by clicking on the white area in the popup. Is there a way to capture and respond to a click outside the white area in the popup?

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle">
          <mx:Script>
              <![CDATA[
                  import mx.managers.PopUpManager;
                  private function clickHandler():void {
                      var popup:Dialog = PopUpManager.createPopUp(this, Dialog, true) as Dialog;
                      PopUpManager.centerPopUp(popup);
                  }
              ]]>
          </mx:Script>
      <mx:Button id="button" label="Click" click="clickHandler()" />
      </mx:Application>

       

      Dialog.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"  click="closePopup();"  >
          <mx:Script>
              <![CDATA[
                  import mx.managers.PopUpManager;
                  private function closePopup():void {
                      PopUpManager.removePopUp(this);
                  }
              ]]>
          </mx:Script>
          <mx:Canvas width="100" height="100" backgroundColor="0xffffff" />
      </mx:Canvas>

        • 1. Re: Event handler for a popup
          rtalton Level 4

          Use the PopUpManager's mouseDownOutside event.

           

          Add this to your main app:

          private

           

           

          var popup:Dialog;

           

          Modify your method like this:

           

          private function clickHandler():void {

          popup = PopUpManager.createPopUp(

          this, Dialog, true) as Dialog;

          popup.addEventListener(

          'mouseDownOutside', closeWindow);

          PopUpManager.centerPopUp(popup);

          }

           

          Add this new method:

           

          private function closeWindow(event:MouseEvent):void {

          PopUpManager.removePopUp(popup);

          }

          1 person found this helpful
          • 2. Re: Event handler for a popup
            Flex harUI Adobe Employee

            <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"  click="closePopup();" 

            initialize="listenForMouseDownOutside()">

                <mx:Script>

                    <![CDATA[

                        import mx.managers.PopUpManager;

                        private function closePopup():void {

                            PopUpManager.removePopUp(this);

                        }

             

                private function listenForMouseDownOutside():void

                {

                    addEventListener("mouseDownOutside", mouseDownOutsideHandler);

                }

                private function mouseDownOutsideHandler(event:Event):void

                {

                    closePopup();

                }

                    ]]>

                </mx:Script>

                <mx:Canvas width="100" height="100" backgroundColor="0xffffff" /