Skip navigation
Currently Being Moderated

Restoring Window

Aug 6, 2010 4:48 AM


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?




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: 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: 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..

  • Currently Being Moderated
    Aug 6, 2010 9:04 AM   in reply to Way2Death

    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


                    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.



    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points