Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Jan 07, 2015 Jan 07, 2015

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?

TOPICS
ActionScript
491
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 07, 2015 Jan 07, 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.

Translate
LEGEND ,
Jan 07, 2015 Jan 07, 2015
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines