0

I have three different buttons. When you click one of the buttons, it is supposed to activate the stageSelect function, which should then output the button's number.

But when I do that, I get the error in the title. What am I doing wrong here?

package {
    import flash.display.MovieClip;
    import flash.display.SimpleButton;
    import flash.events.MouseEvent;
    import flash.ui.Mouse;

    public class MenuScreen extends MovieClip {
        public function MenuScreen() {
            Mouse.show();
            selectGrass.addEventListener(MouseEvent.CLICK, stageSelect, 1);
            selectDirt.addEventListener(MouseEvent.CLICK, stageSelect, 2);
            selectGravel.addEventListener(MouseEvent.CLICK, stageSelect, 3);
        }

        public function stageSelect(stageID:Number) {
            trace(stageID);
        }
    }
}
Pikamander2
  • 7,332
  • 3
  • 48
  • 69
  • You cannot pass parameters to event listeners that way. See http://stackoverflow.com/questions/1464925/passing-parameters-to-event-listeners-handlers – Antoine Lassauzay Nov 29 '12 at 15:40

1 Answers1

3

this is because the third param for the method addEventListener is useCapture which requires a boolean saying that you wish to grab the event during the capture phase before bubbling. You are calling

selectGrass.addEventListener( MouseEvent.CLICK, StageSelect, 1);

What you need to do instead is

selectGrass.addEventListener( MouseEvent.CLICK, grassSelected);
selectDirt.addEventListener( MouseEvent.CLICK, dirtSelected);

private function grassSelected(event:MouseEvent):void{
    // do grass stuff
}

private function dirtSelected(event:MouseEvent):void{
    // do dirt stuff
}
Jason Reeves
  • 1,716
  • 1
  • 10
  • 13