6 Replies Latest reply on Nov 11, 2011 3:27 AM by Arivu India

    Display message box while closing the window by using closing option (X) of the window

    anandbk Level 1

      Hi Guys,

       

      Can anyone help me how to display message/alert box when user clicks  Close option (X) of the window in flex ?

       

      Like in html we can handle it by using,

      window.onbeforeunload = function(){return "Are you sure you want to Exit";}

       

      Is there anything in Flex similar to "window.onbeforeunload" of HTML which can handle Close option (X) of the window ?

      If not, can anyone help me to handle this with sample code.?

       

      Regards,

      Anand.

        • 1. Re: Display message box while closing the window by using closing option (X) of the window
          snkd

          <s:TitleWindow         

                              close="titlewindow1_closeHandler(event)">

           

           

           

                      protected function titlewindow1_closeHandler(event:CloseEvent):void
                      {

           

                           //Show an alert messege 

          Alert.show("Invoice is Already Dispatched.Cannoot Procees further","Operation Restricted",Alert.OK,null, alertCloseHandler,IconWarning);
                    
                      }

           

                      private function alertCloseHandler(event:CloseEvent):void
                      {
                          if (event.detail == Alert.OK)
                          {
                           PopUpManager.removePopUp(event.currentTarget as IFlexDisplayObject);         
                          }
                          else
                          {
                             //no need to close
                          }
                      }

           

          tell me is it ok or not?

          thnx

          • 2. Re: Display message box while closing the window by using closing option (X) of the window
            anandbk Level 1

            Hi,

             

            Thanks for response.


            In my mxml i have not used any kind of <mx:TitleWindow>, etc.
            My flex screen is opened from a jsp page through a hyper link and i dont want to use any window related tags (<mx:TitleWindow>, etc. ).

            It is normal screen with min, max and close option.

             

            Can you please help me with code for closing window wihtout refering to <mx:TitleWindow>, etc.tags. ?

             

            Thanks,

            Anand.

            • 3. Re: Display message box while closing the window by using closing option (X) of the window
              snkd Level 1

              I'm sorry,I have answer you to queston

              Can anyone help me how to display message/alert box when user clicks  Close option (X) of the window in flex ?

              So,then what kind of window you are meaning?

               

              what do you wanna close? browser tab or what ever please mention.I will help you dude.

              • 4. Re: Display message box while closing the window by using closing option (X) of the window
                snkd Level 1

                If you want to close in flex use

                call function in your button click event.

                 

                NativeApplication.exit();

                 

                If your button/(what ever component) is html . javascripst function on click event

                 

                function removeElement(divNum) {
                  var d = document.getElementById('myDiv');
                  var olddiv = document.getElementById(divNum);
                  d.removeChild(olddiv);
                }

                • 5. Re: Display message box while closing the window by using closing option (X) of the window
                  anandbk Level 1

                  Flex Window.png

                  Link in JSP.png

                  Look into these images.

                   

                  Blue color "Synchronization Profile" is a HYPER link in a JSP page.

                   

                  Now, when i click this Hyper link from JSP, a flex window (mxml file) will open with "X" close option. Refer top 1st image.

                   

                  My question is, when i click on red coloured "X" close option of the window, i should display a alert window.

                  How to do that. Hope it is more clear.

                   

                  And as i said i am NOT USING any kind of window related tag (e.g <mx:TitleWindow>, etc) in my mxml file.

                   

                   

                  Thanks,

                  Anand.

                  • 6. Re: Display message box while closing the window by using closing option (X) of the window
                    Arivu India
                    1. It looks you are opening new browser window (if I am correct). In that case you can use your own solution window. onbeforeunload
                    2. If not new browser window, as you mentioned from where you get option “X” to close. Is it your own button/Image and you are handling it on click event?

                    In this case, write javascript function in wrapper HTML/ASP file to show alert message, on click handler function of option X, call the javascript function through ExternelInterface.call()