views:

22

answers:

1

Why won't this ENTER_FRAME event stop firing when I call view_stats_exit before going to view_start?

public function view_start (e:MouseEvent):void
{
    gotoAndStop("start");
}
public function view_stats(e:MouseEvent):void
{
    // Event
    StatsUI.addEventListener(Event.ENTER_FRAME,stats_scroll);
}
public function view_stats_exit (e:MouseEvent):void
{
    StatsUI.removeEventListener(Event.ENTER_FRAME,stats_scroll);
    view_start(null);
}

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

+1  A: 

You can add an event listener to a MovieClip , but you shouldn't do it as a static function , like in your example. The following should work...

  private var ui:StatsUI = new StatsUI();

  public function view_stats(e:MouseEvent):void
  {
     // Event
     ui.addEventListener(Event.ENTER_FRAME,stats_scroll);
  }

  public function view_stats_exit (e:MouseEvent):void
  {
     ui.removeEventListener(Event.ENTER_FRAME,stats_scroll);
     view_start(null);
  }
PatrickS
Thanks, I'll give this a try.
woodscreative