Skip to main content
Inspiring
June 10, 2018
Answered

AS3: Timeline navigation with gotoAndStop(); throws unexpected null object error

  • June 10, 2018
  • 1 reply
  • 2308 views

Here's my code. It seems I can't address the stage. I get a null object reference error at gotoAndStop(3);

private function  exitInvitation(e: MouseEvent😞 void {
simpleBack
.removeEventListener(MouseEvent.CLICK, exitInvitation);
removeChild
(simpleBack);

gotoAndPlay
(3);
}

I'm moving from frame 10 to frame 3. This is clearly a bug. Not even code written on the timeline works. What do I have to listen for to know that my stage object is available?

I've tried adding:

addEventListener(Event.ADDED_TO_STAGE, init);

private function init(e:Event😞void
{
  removeEventListener
(Event.ADDED_TO_STAGE, init);
  gotoAndPlay
(3);
}

Sadly, it doesn't work. I have no idea why other buttons work in my AIR app, but this doesn't. Why is frame 3 null?

This topic has been closed for replies.
Correct answer kglad

that means you have code on line 2 frame 3 of your fla's timeline that's trying to reference a null object.  ie, check your timeline, not the class code.

1 reply

kglad
Community Expert
Community Expert
June 10, 2018

frame 3's not null.  your scope is.

what's this show:

private function  exitInvitation(e: MouseEvent): void {
simpleBack
.removeEventListener(MouseEvent.CLICK, exitInvitation);
removeChild
(simpleBack);
trace(this);
this.gotoAndPlay
(3);
}

SwyzeAuthor
Inspiring
June 10, 2018

Thx, but unfortunately, it didn't work. Here's what I have:

        public function  exitInvitation(e: MouseEvent): void {

            sendInviteBTN.removeEventListener(MouseEvent.CLICK, checkInvitation);

            simpleBack.removeEventListener(MouseEvent.CLICK, exitInvitation);

            removeChild(simpleBack);

            if (displayScore != null && contains(displayScore)) {

            removeChild(displayScore);

            }

            trace(this);

            this.gotoAndPlay(3);

            scoreTXT2.text = "" + userScore;

            usernameTXT.text = "" + username;

        }

This is what I'm getting:

[object Main]

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

    at Main/frame3()[Main::frame3:2]

    at flash.display::MovieClip/gotoAndPlay()

    at Main/exitInvitation()

Line 637 contains this.gotoAndPlay(3);

I have similar code for other buttons and everything works fine there.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
June 10, 2018

that means you have code on line 2 frame 3 of your fla's timeline that's trying to reference a null object.  ie, check your timeline, not the class code.