0

In my program I have a small arrow spinning around, this is the code im using

import flash.events.Event;

var spinSpeed:Number = 2;

function onEnterFrame(event:Event):void{

myMovieClip.rotation += spinSpeed;

}

addEventListener(Event.ENTER_FRAME, onEnterFrame); 



btnnext14.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_11);

function fl_ClickToGoToAndStopAtFrame_11(event:MouseEvent):void
{
    gotoAndStop(39);
}

It works fine and the arrow spins, but when I try and go to the next slide, I get an error #1009

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at pp2_fla::MainTimeline/onEnterFrame()[pp2_fla.MainTimeline::frame38:9]

Anyone know whats wrong?

BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40

1 Answers1

1

This is likely your issue:

On whatever frame the code you posted runs, you add an enter_frame listener. You may not be aware that this enter_frame listener you created will keep running even after you change to frame 39.

Most likely on frame 39 your myMovieClip object doesn't exist anymore, so when your onEnterFrame runs from frame 39 it errors out.

To remedy this, remove the enter_frame listener before you move on to frame 39:

function fl_ClickToGoToAndStopAtFrame_11(event:MouseEvent):void
{
    removeEventListener(Event.ENTER_FRAME, onEnterFrame); 
    gotoAndStop(39);
}
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40