3 Replies Latest reply: Aug 9, 2010 12:51 AM by Way2Death RSS

    Restoring Window



      I'm having a bit of a problem.
      I have an Air application which can be minimized to system tray.
      But the problem is... how do I restore it?
      I've been searching for days, but can't seem to find anything that might be helpful. I've also checked the developers guide.

      So... the question is,
      How do I restore my application?



      ANSWER was:

      How are you "minimizing" your main UI?


      Are you calling NativeWindow.minimize(), setting NativeWindow.visible = false,  or are you destroying the window?


      - In the first case restoring the window is as easy as calling NativeWindow.restore().


      - In the second, setting NativeWindow.visible = true, should do the trick.


      - In the third you will need to manually create the window - lots of details to doing that - which you can read about here: http://livedocs.adobe.com/flex/3/html/help.html?content=WorkingWithWin dows_1.html


      If you are actually wondering about how to listen for mouse events on the SystemTrayIcon - you can do that by calling SystemTrayIcon.addEventListener(ScreenMouseEvent.MOUSE_DOWN) - or by adding a menu to the SystemTrayIcon and handling menu selections.


      You can read more about working with the SystemTrayIcon here:http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS5b3ccc516d4fbf351e63 e3d118666ade46-7dcc.html


      Hope this helps,


      Chris Thilgen

      AIR Engineering



      -- The above question was partially answered, but I didn't seem to have any reply to my second question... which is:


      I''ve tried doing this,

      But I've failed doing so.

      The application window is being destroyed..

      I would like to do .visible = false.


      I've tried doing it like this:


      var app = air.NativeApplication.nativeApplication;
      app.addEventListener(air.Event.EXITING, closeHandler);
      function closeHandler(event)
      this.visible = false;

      But after I do this, I can't do this.visible = true again.

      TypeError: Value undefined does not allow function calls.

      Using just alert also fires the same error.

      I'm using HTML and Javascript


      It seems like EXITING is fired AFTER the window has been closed..

        • 1. Re: Restoring Window

          I spent hours yesterday resolving this very issue. At the end of the day, I was capable only of vacant stares with plenty of drool. Here's the dealio.


          You want to keep the application from exiting when the window is closed by doing 2 things. First


               NativeApplication.nativeApplication.autoExit = false;

               (This step may not be necessary when you do the event capturing below. Can't hurt, might help.)


              Second, when the user clicks on the 'X' in the title bar to close the window, you want to capture that event by listening for




               In this case, the object listening for the event is the root element, WindowedApplication.


               Here's the code for the event handler:


               private function onWindowClosing(event:Event):void {
                          this.visible = false;


               So, the window disappears, but the application still runs in the background. How, then, can users truly exit the application? Like Chris said, use the SystemTrayIcon class, add a menu item that says something like "Exit App", and have that menu item listen for the Event.SELECT event. My app is called Report Viewer, and the system tray icon menu has an item labeled Exit Report Viewer. When the user clicks that menu item, the event handler below fires, and the application exits. The code below is partial; it does not include the steps for loading the icon, creating the SystemTrayIcon object and assigning it a menu.You can find that guidance in the livedocs at http://livedocs.adobe.com/flex/3/html/taskbar_1.html#1030697


                          var exitCommand:NativeMenuItem = iconMenu.addItem(new NativeMenuItem("Exit Report Viewer"));
                          exitCommand.addEventListener(Event.SELECT,function(event:Event):void {
                              NativeApplication.nativeApplication.icon.bitmaps = [];


          The system tray icon also has a menu item labeled Open Report Viewer. It does 2 things: 1) If the window is not visible, but the app is running in the background, it makes the window visible; 2) if the window is merely minimized, it does the same thing that clicking the taskbar icon: it restores the window.


                        var activateCommand:NativeMenuItem = iconMenu.addItem(new NativeMenuItem("Open Report Viewer"));


          And the event handler


               public function activateApplication(event:Event):void {
                          this.visible = true;


          UInfortunately, on Windows XP, the NativeApplication.activate(window) command is not honored. That would save a bit of trouble. But I guess that is protection against those who intend harm.



          • 2. Re: Restoring Window
            Way2Death Community Member

            First of all, thanks for your reply.


            The thing with this is, the Event.CLOSING (air.Event.CLOSING) is never fired.

            EXITING does get fired, but by the time it gets there.. the application is long gone.


            What am I doing wrong


            Here is the code I'm using:


            var iconLoad = new air.Loader();

            var app = air.NativeApplication.nativeApplication;


            app.icon.addEventListener('click', reloadHandler);


            air.addEventListener(air.Event.CLOSING,closeHandler); (<< As you can see)


            function closeHandler(event)


            air.trace("Wanna bet that I never get here?");


                iconLoad.load(new air.URLRequest("icons/AIRApp_16.png"));



            this.visible = false;


            • 3. Re: Restoring Window
              Way2Death Community Member

              My problem has been resolved: http://forums.adobe.com/message/3037489