         // 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);
+        {
+            // 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
+            {
+                systemManager.stage.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeCaptureHandler,
+                                                     true, 0, true);
+            }
+            catch (err:SecurityError)
+            {
+                systemManager.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);
+        {
+            // Same security issue as above
+            try
+            {
+                parentDocument.systemManager.stage.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeCaptureHandler,
+                                                                    true, 0, true);
+            }
+            catch (err:SecurityError)
+            {
+                parentDocument.systemManager.addEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeCaptureHandler,
+                                                              true, 0, true);
+            }
+        }
     }
     
     /**

     */
    private function removeFocusEventListeners():void
    {
        stage.removeEventListener(FocusEvent.KEY_FOCUS_CHANGE, keyFocusChangeHandler);
        stage.removeEventListener(FocusEvent.FOCUS_OUT, focusOutHandler);
        focusListenersAdded = false;
    }
    

     */
    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;
    }
    
