Reputation: 8299
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);
}
}
}
Upvotes: 0
Views: 616
Reputation: 1716
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
}
Upvotes: 3