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

RemoveChild and go next frame don't work

Guest
Feb 11, 2016 Feb 11, 2016

0down votefavorite

I made a game that is based on collecting stars. I have a problem that is at the moment of meeting 4 stars want to share passed to the next frame and removed all the frames tried funkcjii removeChild but message pops up.

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

var health=20;

var score=0;

health_txt.text=health.toString();

score_txt.text=score.toString();

var intervalPunkty = setInterval(addGwiazda,1000);

function addGwiazda(){

  var gwiazda:Gwiazda = new Gwiazda();

  gwiazda.x=Math.ceil(Math.random() * 550);

  gwiazda.y = -50;

  addChild(gwiazda);

  gwiazda.addEventListener(Event.ENTER_FRAME, dropGwiazda);

function dropGwiazda(e:Event){

  var b:Gwiazda = Gwiazda(e.target);

  b.y +=10;

  if(b.y > 400){

  b.removeEventListener(Event.ENTER_FRAME, dropGwiazda);

  removeChild(b);

  }

  if(jazda.hitTestObject(b)){

score ++;

  score_txt.text=score.toString();

  b.removeEventListener(Event.ENTER_FRAME, dropGwiazda);

  removeChild(b);

  if (score == 4){

gotoAndStop(15);

{

    this.parent.removeChildAt(0);

}

}

  }}}

  stop();

TOPICS
ActionScript
239
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
Community Expert ,
Feb 11, 2016 Feb 11, 2016
LATEST

you're trying to reference something that doesn't exist (when that line of code executes).

to find the problematic line of code, click file>publish as>click swf>tick 'permit debugging' and retest.

the line number will be in the error message.

in general, a line like this

   this.parent.removeChildAt(0);

is suspicious and that error can be fixed by using:

if(this.parent && this.parent.numChildren>0){

this.parent.removeChildAt(0);

}

but that's still poor coding and prone to other problems

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