3 Replies Latest reply on Jul 16, 2010 2:10 AM by arvid terzibaschian

    Hide window instead of closing

    arvid terzibaschian

      Hi there!

       

      I am pretty new to flex development and currently trying to hide a window instead of closing it, in order to reopen it later (to keep all the associated variables and window components set).

       

      I experience strange errors across different systems.

       

      Here is the situation:

       

      I got a window:

       

      (in file SearchWindow.mxml)

      <mx:Window xmlns:mx="http://www.adobe.com/2006/mxml"
          layout="absolute"
          width="300"
          height="400"
          systemChrome="none"
          minWidth="300"
          visible="false"
          minHeight="300"
          horizontalScrollPolicy="off"
          verticalScrollPolicy="off"
          creationComplete="init();"
          closing="closing(event)"
          title="My Title">

      ...

      </mx:Window>

       

      The window itself is created as a private variable in the application's mxml:

      (in file MainApplication.mxml)

      public var  searchWindow : SearchWindow = new SearchWindow();

       

      and once set (when the user logged in) when the login window is closed

       

      [...]

       

           searchWindow.open(true);

           searchWindow.nativeWindow.visible = false;    // do not show yet

      [...]


      and opened when the user clicks the search button:

       

      [...]

           searchWindow.activate();

           searchWindow.orderToFront();

      [...]

       

      (in file SearchWindow.mxml)

      the closing event handler looks like this (and is the part that, as it seems to me, does not work)

       

          private function closing(event : Event) : void {
                      event.stopImmediatePropagation();
                      event.stopPropagation();
                      event.preventDefault();
                       // save preferences
                      this.nativeWindow.visible = false;
                      var up : UserPreferences = Application.application.up;
                      up.downloadCenter_downloadPath = downloadPath.nativePath;
                      up.downloadCenter_width = nativeWindow.width;
                      up.downloadCenter_height = nativeWindow.height;
                      up.downloadCenter_x = nativeWindow.x;
                      up.downloadCenter_y = nativeWindow.y;
                  }

       

      As I said, what I am trying to do is to hide the window, not close it. It works on most systems, as mine (Windows 7). But this does not seem to work on some systems (in detail on 1 Windows XP, 2 Unix and 1 Mac system).

       

      What am I doing wrong? What is the correct way to achieve such a functionality?

       

      Thanks in advance for any help!

        • 1. Re: Hide window instead of closing
          BhaskerChari Level 4

          Hi ,

           

          add the below eventListener in the creationComplete of your main application...

           

          nativeWindow.addEventListener(Event.CLOSING,callClosing);

           

          Note the above event is Event.CLOSING but not Event.CLOSE....

           

          Event.CLOSING is called before when the window is about to be close....but Event.CLOSE is dispatcher just when it is about to close...

           

           

          and your close function should now look like ..as below:

           

          private function callClosing(event : Event) : void {
                  event.stopImmediatePropagation();
                  event.stopPropagation();
                  event.preventDefault();
                   // save preferences
                  stage.nativeWindow.visible = false;
                  var up : UserPreferences = Application.application.up;
                  up.downloadCenter_downloadPath = downloadPath.nativePath;
                  up.downloadCenter_width = nativeWindow.width;
                  up.downloadCenter_height = nativeWindow.height;
                  up.downloadCenter_x = nativeWindow.x;
                  up.downloadCenter_y = nativeWindow.y;
              }

           

          If this post answers your question or helps, please kindly mark it as such.


          Thanks,

          Bhasker Chari

           

          • 2. Re: Hide window instead of closing
            arvid terzibaschian Level 1

            Hi there!

             

             

            BhaskerChari wrote:

             

            Hi ,

             

            add the below eventListener in the creationComplete of your main application...

             

            nativeWindow.addEventListener(Event.CLOSING,callClosing);

             

            Note the above event is Event.CLOSING but not Event.CLOSE....

             

            Event.CLOSING is called before when the window is about to be close....but Event.CLOSE is dispatcher just when it is about to close...

             

             

             

             

             

            Shouldn't the following line in the mxml code of the SearchWindow (it is the one to hide) already add the closing event handler? Or do I need to do it manually after the creationComplete has been thrown?

            This is what I already got (see my first post):

             

            <mx:Window xmlns:mx="http://www.adobe.com/2006/mxml" 
                layout="absolute" 
                width="400" 
                height="300" 
                systemChrome="none"
                minWidth="400"
                visible="false"
                minHeight="300"
                horizontalScrollPolicy="off"
                verticalScrollPolicy="off"
                creationComplete="init();"
                closing="closing(event)"
                title="Search VKontakte">

            BhaskerChari wrote:


            and your close function should now look like ..as below:

             

            private function callClosing(event : Event) : void {
                    event.stopImmediatePropagation();
                    event.stopPropagation();
                   event.preventDefault();
                     // save preferences
                    stage.nativeWindow.visible = false;
                    var up : UserPreferences = Application.application.up;
                    up.downloadCenter_downloadPath = downloadPath.nativePath;
                    up.downloadCenter_width = nativeWindow.width;
                    up.downloadCenter_height = nativeWindow.height;
                    up.downloadCenter_x = nativeWindow.x;
                   up.downloadCenter_y = nativeWindow.y;
                }

             

            I did not think about the stage variable yet, but what is there difference to simply use nativeWindow.visible = false?

            I will give it a try

            • 3. Re: Hide window instead of closing
              arvid terzibaschian Level 1

              Hello all!

               

              Indeed the code already worked as is My fault.

              Some code before crashed (only on some systems, which I am still examining) and prevented the closing event handler to finish as expected. Thus, I experienced those weird errors.