title: AS3 - KeyboardEvent.KEY_DOWN in AIR project not triggering handler after removing display objects, and stage.focus not working
body: <p>I am developing an kiosk-like application (a game) which needs to be locked in full screen all the time. I am using as3/flash/AIR for it. Things started well at first, and for the most part all works fine.. but there is a mystery brewing somewhere which I haven't been able to figure out... That's where your help would be greatly appreciated!</p>
  
  <p>The way I handled this problem is by adding at the very beginning of the app:</p>
  
  <pre><code>stage.addEventListener(KeyboardEvent.KEY_DOWN, playerOnKeyDown);
  </code></pre>
  
  <p>Then, on my playerOnKeyDown function:</p>
  
  <pre><code>function playerOnKeyDown(event:KeyboardEvent):void
  {
      if (event.keyCode == Keyboard.ESCAPE)
      {
          event.preventDefault();
          //More code here opening out menus, etc, etc.)
      }
  }
  </code></pre>
  
  <p>So, all of this worked just fine, but of course I needed to also bring along: </p>
  
  <pre><code>stage.focus = stage;
  </code></pre>
  
  <p>into the party, otherwise, when removing objects - as in removeChild() - the event firing wouldn't behave as I wanted, because flash changed the focus elsewhere in the display list. </p>
  
  <p>I have been careful to add the focus to the stage every time a remove a "child", and it works great everywhere, except for one time in the entire run, right after I remove an object from an externally loaded swf. </p>
  
  <p>I still add the lines as it should be expected to work:</p>
  
  <pre><code>removeChild(childFromLoadedSWF);
  stage.focus = stage;
  </code></pre>
  
  <p>except that when I hit the any key, the event won't trigger my function, and if I hit the ESC key, it takes me out of full screen (its default behavior), once again, circumventing completely my listener function playerOnKeyDown.</p>
  
  <p>The strange thing is that right before doing this, the line:</p>
  
  <pre><code>stage.hasEventListener(KeyboardEvent.KEY_DOWN))
  </code></pre>
  
  <p>traces true!</p>
  
  <p>The focus is on the stage, the listener is on, and yet when pressing the ESC key the default behavior is ignoring my function completely.... </p>
  
  <p>What could be causing this? </p>
  
  <p>THANK YOU!!</p>