Skip to main content
Participating Frequently
February 6, 2014
Answered

1009 null object reference

  • February 6, 2014
  • 1 reply
  • 1099 views

Hi, I'm creating an android game and everything goes wrong when you lose and the "lose screen" is displayed...

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at rock/destroyEnemy()

          at Function/main/$construct/endGame()

          at Function/main/$construct/Loop()

(this is in the main class file)

for each (var enemy:rock in aEnemyArray)

                                        {

                                                  //destroy enemy in loop

                                                  enemy.destroyEnemyAgain();

                                                  //remove enemy from array

                                                  aEnemyArray.splice(0, 1);

                                        }

(this is in the enemy class file)

public function destroyEnemy():void

                    {

   parent.removeChild(this)

   removeEventListener(Event.ENTER_FRAME, enemyLoop);

                    }

The thing is that if you don't shot at he rocks there´s no problem, but when you hit one, at the time you lose, the error comes.

Thanks.

This topic has been closed for replies.
Correct answer Ned Murphy

yeah, that is. Any idea how can I fix it?


Use the trace function to track things down.  If something exists one memoent and not the next, you need to intercept that processing between that existence change and make sure you are not still looking for the object.  If you are retaining an array that references the object then make sure you remove it from that array before the next loop cyce starts.

1 reply

Ned Murphy
Legend
February 7, 2014

Which is line 108 of the rock.as file?

Participating Frequently
February 7, 2014

enemy.destroyEnemyAgain();

Participating Frequently
February 7, 2014

in the code its enemy.destroyEnemy(); not enemy.destroyEnemyAgain(); ... just forget the "Again"