Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8445661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:42:49+00:00 2026-06-10T09:42:49+00:00

I have a code to pause the game, and it runs the pause function

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:42:51+00:00Added an answer on June 10, 2026 at 9:42 am

    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 ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with this code right here: - (void)fetchedData:(NSData *)responseData { //parse
I have a pong type of game and I want the spacebar to pause
I have the following JavaScript code: var cILo=true; var img1=images/title-2a.png; var img2=images/title-2b.png; function loadblinker()
Hi I have this code to parse JSON on JQUERY var json_text2 = $.parseJSON('{data:[[1340650436,2.00000],[1340736844,4.00000]],label:Waist
I have code straight from Google's dev guide: Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(market://details?id=com.example.android));
I have this code snippet: DateFormat formatter1; formatter1 = new SimpleDateFormat(mm/DD/yyyy); System.out.println((Date)formatter1.parse(08/16/2011)); When I
I have date formatted in this way: 2010-02-04T00:00:00 I use this code to parse
I have the following code : XDocument xResponse = XDocument.Parse(strXMLResponse); var vMyData = from
I have used following code to convert string to json and parse it. String
I have a working JavaScript code below which dynamically creates JSON object using JSON.parse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.