Search code examples
actionscript-3flashmenuaddeventlistenersubmenu

addEventListener and gotoAndStop for a menu in a game gives error


I'm new at flash as3. Today, I am trying to code a menu in a game which will refer to a startscreen for a game to show the buttons for the game.

In this startscreen, there is a button to link back to the menu. It doesn't work. I am getting this,

Error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at SuperSpill_fla::MainTimeline/frame1()

Solution

  • It looks like to me the only possible thing that could have happened is that mus doesn't exist anymore. This suggests that the code is running in a frame where mus is no longer on stage.

    I would expect that in most versions of the Flash Player that the frame wouldn't fully render between goToAndStop and the next line, but my suggestion would be to either swap the order of those lines or change it to

    event.currentTarget.removeEventListener(MouseEvent.CLICK, musSpill)