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

1009 null object reference

New Here ,
Feb 06, 2014 Feb 06, 2014

Copy link to clipboard

Copied

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.

TOPICS
ActionScript

Views

914

Translate

Translate

Report

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 , Feb 06, 2014 Feb 06, 2014

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.

Votes

Translate

Translate
LEGEND ,
Feb 06, 2014 Feb 06, 2014

Copy link to clipboard

Copied

Which is line 108 of the rock.as file?

Votes

Translate

Translate

Report

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
New Here ,
Feb 06, 2014 Feb 06, 2014

Copy link to clipboard

Copied

enemy.destroyEnemyAgain();

Votes

Translate

Translate

Report

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
New Here ,
Feb 06, 2014 Feb 06, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 06, 2014 Feb 06, 2014

Copy link to clipboard

Copied

You indicated that line is in the main file in your first posting, not the rock.as file.

chances are that for loop is trying to target an enemy after it has been removed already.  Try tracing the enemy on a line before that to confirm that  is the case.

Votes

Translate

Translate

Report

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
New Here ,
Feb 06, 2014 Feb 06, 2014

Copy link to clipboard

Copied

sorry, I´m a mess right now.

the line is parent.removeChild(this).

I'll try that and let you know what happen

Votes

Translate

Translate

Report

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
New Here ,
Feb 06, 2014 Feb 06, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 06, 2014 Feb 06, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
New Here ,
Feb 07, 2014 Feb 07, 2014

Copy link to clipboard

Copied

Solved! thank you so much!

Votes

Translate

Translate

Report

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
LEGEND ,
Feb 07, 2014 Feb 07, 2014

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

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