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 8112875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:39:10+00:00 2026-06-06T02:39:10+00:00

This is a little snippet from a little flash game I’m working on: This

  • 0

This is a little snippet from a little flash game I’m working on:

This bit from my GamePlayScreen class:

public function handleKeyboard(e:KeyboardEvent):void {
        if(e.type == KeyboardEvent.KEY_DOWN && e.keyCode == Keyboard.ENTER) {
            var enemy:EnemyShip = new EnemyShip();
            enemyships.push(enemy);
            addChild(enemyships[enemyships.length-1]);
        }
    }

and this bit is causing the error (I marked the line with *)

for each (var enemy:EnemyShip in Game.gameplay.enemyships) {
            if(this.hitTestObject(enemy)) {
                *enemy.parent.removeChild(enemy);
            }

gameplay is an instance of GamePlayScreen declared in my document class Game. I already traced enemy.parent and it told me it was [Object GamePlayScreen], yet the error tells me it is null?

This is the error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Laser1/moveUp()[C:\Dev\Projects\Gamedev\Flash\classes\Laser1.as:23]

I tryed everything, tracing on every line, and still no results… Even when I use

if(Game.gameplay.contains(enemy) {
    enemy.parent.removeChild(enemy);
}

it continues to stumble on this error again…
I am clueless…

  • 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-06T02:39:12+00:00Added an answer on June 6, 2026 at 2:39 am

    A simple solution may be checking if the value is not null and the enemy still has a parent.

    for each (var enemy:EnemyShip in Game.gameplay.enemyships) {
      if(enemy && enemy.parent && this.hitTestObject(enemy)) {
        enemy.parent.removeChild(enemy);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made this little function from code snippets around the net. It does what
I have taken this little snippet straight out of some code I'm working on:
This is a snippet from a prototype class i am putting together. The scoping
I'm learning C right now, and I copied this little snippet straight from the
I'm playing around with list comprehensions and I came across this little snippet on
found this little code snippet that seems to do what i want, but im
I have a little snippet that formats a date for a timestamp like this:
I am a little confused by this snippet of code (presented in the CocoaFundamentals
This little bit of syntax has been a bit of a confusion for me
The following snippet is from a little app I wrote using the Qt framework.

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.