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

Null Object Reference Error Problem

New Here ,
Jul 11, 2013 Jul 11, 2013

Hello, I'm having a problem with a class(_gameModel), being instantiated in another class(_gameController), and when I try to reference the _gameModel class in the _gameController class I get a null Object reference error even though I know that the class is instantiated at the top of the _gameController class page.  I thought that if it was instantiated in the class then I wouldn't have this problem but I am. Anyone know what the problem is? thanks

TOPICS
ActionScript
1.0K
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 , Jul 11, 2013 Jul 11, 2013

I don't see anything being instantiated relative to anything you've indicated that is, so I can't say if that is an issue or not. 

Did you show only a portion of the error message or is there more information in it?  Show the complete error message if that is not all of it.

Based on that function involving "EnterFrame" in the name, my suspiscions fall to wondering if you are catching that error after the object has been removed on a previous pass thru the function.  How do the traces look from th

...
Translate
LEGEND ,
Jul 11, 2013 Jul 11, 2013

Show the code related to this issue as well as the complete error message.  BEfore showing the message, go into your Flash Publish Settings and select the option to Permit Debugging so that the error message might be more complete with the info it offers.

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
New Here ,
Jul 11, 2013 Jul 11, 2013

Here's the game loop function where I am having the problem and below that is the function where added the _pauseSound to the _gameModel.screen Sprite. I first tried to remove _pauseSound with this:

_gameModel.screen.removeChild(_pauseSound); but I get a #2025 Error: supplied DisplayObject must be a child of the caller, so I changed it to _pauseSound.parent.removeChild(_pauseSound); and I get the null object error. I have _pauseSound instantiated at the top of the page so I don't know what the problem is.

public function runGameEnterFrame(e:Event):void {

                              trace("_pauseSound = "+_pauseSound);

                                        screenText.update();

                                        timeDifference = getTimer() - lastTime;

                                        lastTime = getTimer();

                                        checkSystemState();

                                        systemFunction();

                                        frameCounter.countFrames();

                                        if(_gameModel.updateMusVol){

                                                  soundController.updateSoundVolume(true);

                                        }

                                        if(_gameModel.updateSoundVol){

                                                  soundController.updateSoundVolume(false);

                                        }

                                        if(_gameModel.gotoIntro){

                                                  _docClass.gotoAndStop(1);

                                                  trace("_pauseSound2 = "+_pauseSound);

                                                  trace("_pauseSound.parent = "+_pauseSound.parent);-------This is 'null'

                                                  trace("_gameModel.screen = "+_gameModel.screen );

                                                  _pauseSound.parent.removeChild(_pauseSound);-----error

                                                  _gameModel.pauseAndMuteAdded = false;

                                                  _levelTwo.dispose();

                                                  _gameModel.gotoIntro = false;

                                                  }

                    }

public function addPauseEtc():void{

                              if(_gameModel.pauseAndMuteAdded == false){

 

                                                  _pauseSound.addPauseSoundButtons(470,20,500,20,540,20,580,20);

                                                            _gameModel.screen.addChild(_pauseSound);

                                                            _gameModel.pauseAndMuteAdded = true;

                                                  }

                    }

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
LEGEND ,
Jul 11, 2013 Jul 11, 2013

I don't see anything being instantiated relative to anything you've indicated that is, so I can't say if that is an issue or not. 

Did you show only a portion of the error message or is there more information in it?  Show the complete error message if that is not all of it.

Based on that function involving "EnterFrame" in the name, my suspiscions fall to wondering if you are catching that error after the object has been removed on a previous pass thru the function.  How do the traces look from that first line in the function?  Does is come up as null when the error occurs but looks okay before that?

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
New Here ,
Jul 11, 2013 Jul 11, 2013

I changed a few things and it seems to be working for now anyway, thank you for your advice.

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
LEGEND ,
Jul 12, 2013 Jul 12, 2013
LATEST

You're welcome

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