     private function window_closeHandler(event:Event):void
     {
         dispatchEvent(new Event("close"));
+        
+        // Event for Automation so we know when windows 
+        // are created or destroyed.
+        if (ApplicationGlobals.application)
+        {
+            ApplicationGlobals.application.dispatchEvent(
+                new WindowExistenceEvent(WindowExistenceEvent.WINDOW_CLOSE, 
+                                         false, false, this));
+        }
     }
     
     /**

import mx.events.AIREvent;
import mx.events.FlexEvent;
import mx.events.FlexNativeWindowBoundsEvent;
import mx.managers.CursorManagerImpl;
import mx.managers.FocusManager;
import mx.managers.ICursorManager;

            _nativeWindow.addEventListener("deactivate", nativeWindow_deactivateHandler, false, 0, true);
            
 			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
 			
 			//'register' with WindowedSystemManager so it can cleanup when done.
 			sm.addWindow(this);
        }
