Pikamander2
Pikamander2

Reputation: 8299

AS3: int used where a boolean value was expected

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

Answers (1)

Jason Reeves
Jason Reeves

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

Related Questions