What about it is not working? If it's what you show in red, it's because that should have quotes around the string. Other than that, the removeChild call will function for any key since it is outside the conditional

What you should do is go into your Flash Publish Settings and select the option to Permit Debugging. What this often does is adds line numbers to the error message to indicate where the problemed code is.

You should format your code properly, it is very difficult to read all spread out and oddly indented as you show it. I had to take you code and reformat it just to see what you have. After removing any code related to things I do not have, I ran the file and the textfield displayed time counting, and when I press the spacebar I get the trace message: "The spacebar key was pressed"

So it is working fine for what the code tells it to do. Since customPanel was never added as a child, it is not going to be removed (you create another new instance, but that other new instance is not customPanel)