AS3:int用于需要布尔值的位置

时间:2012-11-29 15:21:12

标签: actionscript-3 events parameters addeventlistener

我有三个不同的按钮。单击其中一个按钮时,应该激活stageSelect功能,然后输出按钮的编号。

但是当我这样做时,我会在标题中收到错误。我在这里做错了什么?

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);
        }
    }
}

1 个答案:

答案 0 :(得分:3)

这是因为addEventListener方法的第三个参数是useCapture,它需要一个布尔表示你希望在冒泡前的捕获阶段抓取事件。你在打电话

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

您需要做的是

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
}