KeyboardEvent problem

i am having some problems with the KeyboardEvents in AS3.
i am having a class called Man, that has the following code in the constructor. there is a movieclip in the library, that is based on this class.
here’s the code in the constructror:


stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

and then of course i have the other two functions onKeyDown and onKeyUp in the same class. in these functions, i do a trace of the KeyboardEvent.keyCode.

then in my document class, i create a new instance of the Man class and addChild it to the display list. when i publish, i get an error that says:


TypeError: Error #1009: Cannot access a property or method of a null object reference.

i thought i have added the Man class into the display list and i should be able to access the stage but why is it null?

the reason i thought of adding the listeners to the stage is because if i add it to just the Man class itself, the keys won’t get detected. clicking on the Man instance on the stage does not change the focus to it. and even setting the stage.focus = Man cannot get the focus back to the man after i defocus it to elsewhere.

i kind of need a global keyboard event