Weird Game Glitch O.o

Ok, so this has me completely baffled. I have the code all set up so if the character is hit. game over is displayed and if you click a button it restarts. The problem is when it restarts the character is sometimes randomly not added to the stage… the character object isn’t null though… >.> The program doesn’t identify any game errors.

If he gets hit this code is called

public function endGame()
        {
            gameOver = true;
            projectileList = null;
            mcBob.deleteBob();
            trace("game over");
            myNewTimer.stop();
            removeChild(mcBoundry);
            removeChild(mcBackground);
            stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDown);
            stage.removeEventListener(KeyboardEvent.KEY_UP, keyUp);
            resetGame();






        }

that calls this function

private function resetGame()
        {


            myFormat = new TextFormat();
            myFormat2 = new TextFormat();
            myFont =  new Font1();
            instrText = new TextField();
            gameOverText = new TextField();
            myFormat2.font = myFont.fontName;
            myFormat2.size = 15;
            myFormat.font = myFont.fontName;
            myFormat.size = 54;
            instrText.embedFonts = true;
            instrText.defaultTextFormat = myFormat2;
            instrText.text = "press any button to restart";
            instrText.x = 179;
            instrText.y = 268;
            instrText.width = 400;
            instrText.height = 100;
            instrText.selectable = false;
            gameOverText.embedFonts = true;
            gameOverText.defaultTextFormat = myFormat;
            gameOverText.text = "game over";
            gameOverText.x = 130;
            gameOverText.y = 173;
            gameOverText.width = 300;
            gameOverText.height = 200;
            gameOverText.selectable = false;
            addChild(gameOverText);
            addChild(instrText);
            stage.addEventListener(KeyboardEvent.KEY_DOWN, restart);




        }

which calls this function(kind of resets the game :P)

private function restart(event:KeyboardEvent)
        {
            stage.removeEventListener(KeyboardEvent.KEY_DOWN, restart);
            stage.focus = stage;
            mcBob = new Bob(285,210);
            addChild(mcBob);
            if (mcBob != null)
            {
                trace(mcBob);
            }
            else
            {
                addChild(mcBob);
            }
            gameOver = false;
            stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
            stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
            removeChild(instrText);
            removeChild(gameOverText);
            mcBoundry = new Boundry();
            mcBoundry.x = 1.6;
            mcBoundry.y = .4;
            addChild(mcBoundry);
            mcBackground = new Background();
            addChildAt(mcBackground,0);
            projectileList = new Array();
            myTimer = new Timer(333,1);
            myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, startProject);
            myTimer.start();
        }

I don’t really get it :confused:

but btw this is my first flash game!! :smiley:

Thanks for the help, you guys rock :slight_smile: