Skip to main content
XenoHarry
Participant
January 7, 2015
Answered

[Fault] exception, information=TypeError: Error #1009: Cannot access a property or method of a null object reference.

  • January 7, 2015
  • 1 reply
  • 514 views

I'm creating a 2D game and I was creating an event for when my character touches a gem, it 'collects' the gem and the image is removed. However when playing the game and the character touches the gem the game crashes and I am presented with the error.

This is the code that I added:

public function Collect():void

  {

  if (FireBoy.hitTestObject(Green))

  {

  Green.parent.removeChild(Green);

  }

  }


I have checked where the error is coming from and apparently the error lies with the line Green.parent.removeChild(Green);

What do I need to do to fix the error and to allow my character to still collect the gem?

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

What is driving the Collect function to execute?  If it is involved in some form of EnterFrame processing it might be a case where you are still trying to remove Green after it has already been removed.  Try putting a trace just before that line to see what the status of Green is before you remove it.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
January 8, 2015

What is driving the Collect function to execute?  If it is involved in some form of EnterFrame processing it might be a case where you are still trying to remove Green after it has already been removed.  Try putting a trace just before that line to see what the status of Green is before you remove it.