      */
     private function removeFocusEventListeners():void
     {
-        stage.removeEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeHandler);
-        stage.removeEventListener(FocusEvent.FOCUS_OUT, focusOutHandler);
+        // Same security issue as addFocusEventListeners()
+        try
+        {
+            stage.removeEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeHandler);
+            stage.removeEventListener(FocusEvent.FOCUS_OUT, focusOutHandler);
+        }
+        catch (err:SecurityError)
+        {
+            systemManager.removeEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeHandler);
+            systemManager.removeEventListener(FocusEvent.FOCUS_OUT, focusOutHandler);
+        }
+        
         focusListenersAdded = false;
     }
     

        // Add a key focus change handler at the capture phase. We use this to 
        // determine focus direction in the setFocus() call.
        if (systemManager)
            systemManager.stage.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeCaptureHandler,
                                                 true, 0, true);
        else if (parentDocument && parentDocument.systemManager)
            parentDocument.systemManager.stage.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeCaptureHandler,
                                                 true, 0, true);
    }
    
    /**

     */
    private function addFocusEventListeners():void
    {
        // If we get a security error because we're not allowed to add event listeners to the stage, 
        // then just add them to the systemManager instead because we could be an untrusted app.
        try
        {
            stage.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeHandler, false, 1, true);
            stage.addEventListener(FocusEvent.FOCUS_OUT, focusOutHandler, false, 0, true);
        }
        catch (err:SecurityError)
        {
            systemManager.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeHandler, false, 1, true);
            systemManager.addEventListener(FocusEvent.FOCUS_OUT, focusOutHandler, false, 0, true);
        }
        
        focusListenersAdded = true;
    }
    
