             window_displayStateChangeHandler)
         systemManager.stage.nativeWindow.addEventListener(
             "closing", window_closingHandler);
-
+        systemManager.stage.nativeWindow.addEventListener(
+            "close", window_closeHandler, false, 0, true);
+            
+        // For the edge case, e.g. visible is set to true in
+        // AIR xml file, we fabricate an activate event, since Flex 
+        // comes in late to the show.
+        if (systemManager.stage.nativeWindow.active) 
+            dispatchEvent(new Event("windowActivate"));
+                        
+        systemManager.stage.nativeWindow.addEventListener(
+            "activate", nativeWindow_activateHandler, false, 0, true);
+        systemManager.stage.nativeWindow.addEventListener(
+            "deactivate", nativeWindow_deactivateHandler, false, 0, true);
+                        
         systemManager.stage.nativeWindow.addEventListener(
             NativeWindowBoundsEvent.MOVING, window_boundsHandler);
 

    	else
    		dispatchEvent(event);
    }

    /**
     *  This is a temporary event handler which dispatches a initialLayoutComplete event after
     *  two updateCompletes. This event will only be dispatched after either setting the bounds or

 *  @eventType mx.events.AIREvent.APPLICATION_DEACTIVATE
 */
[Event(name="applicationDeactivate", type="mx.events.AIREvent")]

/**
 *  Dispatched after this application window has been activated.
 *
 *  @eventType mx.events.Event.ACTIVATE
 */
[Event(name="windowActivate", type="flash.events.Event")]

/**
 *  Dispatched after this application window has been deactivated.
 *
 *  @eventType mx.events.Event.DEACTIVATE
 */
[Event(name="windowDeactivate", type="flash.events.Event")]
 
/**
 *  Dispatched after this application window has been closed.
 *
 *  @eventType flash.events.Event.CLOSE
 *
 *  @see flash.display.NativeWindow
 */
[Event(name="close", type="flash.events.Event")]

/**
 *  Dispatched before the WindowedApplication window closes.
