This was something that had me banging my head for 2 hours before I figured it out.
I decided to post it here, to help others not pull their hair out :).
Essentially the bug was I was not receiving the keyboard event from within my flash builder environment (The same bug/issue is visible with adobe flash cs5). I set the stage.focus = stage, did not help. I added other event listeners (mouse_down, frame_enter) which worked fine, I added MovieClip children and listened for events on those children, still the same issue.
package
{
public class Test extends Sprite
{
public function Test()
{
this.addEventListener(Event.ADDED_TO_STAGE,init);
}
public function init(stage:Stage):void
{
this.removeEventListener(Event.ADDED_TO_STAGE,init);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
}
private function keyPressed(e:KeyboardEvent):void
{
trace("keyPressed");
}
private function keyReleased(e:KeyboardEvent):void
{
trace("keyReleased");
}
}
}