Q: Parameter child must be non-null error in AS3 I have a code to pause the game, and it runs the pause function as shown:
public function onKeyPress(keyboardEvent:KeyboardEvent) :void
{
    //Check for pause
    if(keyboardEvent.keyCode == Keyboard.P)
    {
        //If the timer is still running
        if(gameTimer.running)
        {
            gameTimer.stop();
            Mouse.show();
            pauseText = new PauseText();
            pauseText.x = 150;
            pauseText.y = 100;
            addChild(pauseText);
            //If the player is using the mouse, resume by clicking on the player
            if(mouseControl)
            {
                player.addEventListener(MouseEvent.CLICK, resumeGame);
                pauseText.pauseInformation.text = "click on yourself";
            }
            else
            {
                pauseText.pauseInformation.text = "press 'p'";
            }
        }
        else
        {
            //Only allow the player to resume with P IF he is using the keyboard
            //This prevents cheating with the mouse.
            if(!mouseControl)
            {
                gameTimer.start();
                removeChild(pauseText);
                pauseText = null;
            }
        }
    }
}

The game runs perfectly fine. On my first playthrough, the pause functions work. However, if later I die and restart the game, then pause it, I get the following message:
TypeError: Error #2007: Parameter child must be non-null.
    at flash.display::DisplayObjectContainer/removeChild()
    at Game/onKeyPress()

The game still runs fine though. However, everytime I pause, or unpause, this error appears. If I die again, restart, then pause, TWO of these errors appears. From what I can gather it seems as if it attempts to remove the pauseText…but I've been removing it just fine on the first playthrough, I've used removeChild() then set as null for other parts of my code and it works fine. Additionally, if I add a trace("a"); statement right after the function header, I get the error before the "a" appears on the output panel.
What's wrong?
Additional notes:
If I don't use the pause function at all for my first playthough, there is no error when I call it up on my second playthrough.

A: put removeChild into 'if' ,this will solve error :
if(pauseText.parent){
    pauseText.parent.removeChild(pauseText);
}

but You should anyway check what is the source of problem , maybe 'gameTimer.running' is false on beggining ?

A: You probably instantiate another Game object (the one that contains the whole game) while not removing the previous game's event listener. That would explain such behavior, since you have more than one KeyboardEvent.KEY_DOWN listener active, and note that when you're stopping the game, you most likely stop the timer in it, so the "else" clause of your "if (gameTimer.running)" statement is executed, but the timer was effectively stop without pauseText to be generated. So, you miss a 
removeEventListener(KeyboardEvent.KEY_DOWN,onKeyPress);

in your game destruction code.

A: if (!mouseControl) {
    gameTimer.start();
    if (pauseText && contains(pauseText)) {
        removeChild(pauseText);
        pauseText = null;
    }
}

