0

我有三个不同的按钮。当您单击其中一个按钮时,它应该激活 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);
        }
    }
}
4

1 回答 1

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
}
于 2012-11-29T15:32:09.020 回答