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

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

Explorer ,
Jun 10, 2018 Jun 10, 2018

Copy link to clipboard

Copied

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?

TOPICS
ActionScript

Views

1.7K

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

Community Expert , Jun 10, 2018 Jun 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.

Votes

Translate

Translate
Community Expert ,
Jun 10, 2018 Jun 10, 2018

Copy link to clipboard

Copied

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);
}

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
Explorer ,
Jun 10, 2018 Jun 10, 2018

Copy link to clipboard

Copied

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.

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
Community Expert ,
Jun 10, 2018 Jun 10, 2018

Copy link to clipboard

Copied

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.

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
Explorer ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

Yes, you were right. The problem is, that the timeline code referred to a button that's on the stage, but I looked into the code and I don't call for its removal. It disappears on it's own, it seems, which is pretty weird. So I press a button at frame 3 that goes to  frame 9, and when I press the back button, it goes back to frame 3. Except, somehow, one of my buttons located on the stage gets removed, but I don't use removeChild along the way, so I have no idea how animate cc can remove a button that was placed there physically and not throughout code.

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
Community Expert ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

unless that button is created on frame 3, or is never removed, that problem is predicable.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

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
Explorer ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

What you're saying is, it's better to create them dynamically and then remove them from the stage along with  eventlisteners? I susually, do that, but sometimes placing them manually on stage is more comfortable.

This button doesn't exist on frames 1 and 2, and is "only" located on frame 3 (it's not added dynamically).

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
Community Expert ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

the less you use the timeline, the less chance of difficult to debug errors.

but if an object only exists on one frame (and therefore is not tweened), i wouldn't expect that error.

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
Explorer ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

It's not. It's a completely static button without any timeline animation, or any animation whatsoever, but when I click back button at frame 9, the button on frame 3 literally disappears from the stage. Is there any way to trace an object located on a  different frame we're currently at? I've looked throught the code and didn't see anything that would remove the butto or switched its visible property to false.

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
Community Expert ,
Jun 11, 2018 Jun 11, 2018

Copy link to clipboard

Copied

LATEST

you can't reference it from a frame where it doesn't exist.

you can enumerate all the objects on the main timeline when you return to frame 3 and see that it is still there, but has lost its previous reference (ie, instance name):

for (var i:int=0;i<this.numChildren;i++){

trace(this.getChildAt(i),this.getChildAt(i).name);

}

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