Actionscript 3: gotoAndStop

actionscriptactionscript-3buttonflashframe

I have a project in Flash CS3 that's giving me a bit of trouble. I have a movieclip, and in that movieclip, I have a button. The movieclip is named bg and the button tohallway_btn. My coding is on the stage on a layer, not on classes or in a package, or anything of that sort. This is my coding:

bg.tohallway_btn.addEventListener(MouseEvent.CLICK, tohallwayClick);
function tohallwayClick(event:MouseEvent):void{
        gotoAndStop (141);
    }

It seems simple enough, yet when I debug and the button is clicked, the flash player freezes over. I have absolutely no idea what's causing it to do this.

I get a type error in output as well:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Camille_fla::MainTimeline/enterF()[Camille_fla.MainTimeline::frame140:130]

Any help is appreciated.

Best Answer

An onEnterFrame listener was called and not removed that was referencing an object (bg) that was not on the stage after the goto call.

function tohallwayClick(event:MouseEvent):void {
    **removeEventListener(Event.ENTER_FRAME, enterF);**
    gotoAndStop(141);
}
Related Topic