如何在动作脚本中禁用键盘键?
我正在创建 Flash“记忆”游戏,想发现 2 张相等的卡片。当发现第二张牌时,它会显示 750 毫秒,在此期间玩家不能做任何动作。当我使用这个mouseChildren = false;
播放器时,这次不能用鼠标点击,但他可以使用键盘箭头/回车/空格/制表键……我需要暂时禁用它。
这是我的代码的一部分:
{
trace("Wrong");
_message = "Wrong";
message_txt.text = _message;
_secondCard = event.currentTarget;
var timer:Timer = new Timer(750, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, flipBack);
timer.start();
stage.addEventListener(KeyboardEvent.KEY_DOWN, blindKeyboard);//added here
stage.addEventListener(KeyboardEvent.KEY_UP, blindKeyboard);//added here
mouseChildren = false;
}
}
function blindKeyboard(e:KeyboardEvent):void{ //added here function
e.preventDefault();
e.stopPropagation();
}
protected function flipBack(event:TimerEvent):void
{
_firstCard.gotoAndPlay("flipBack");
_secondCard.gotoAndPlay("flipBack");
_firstCard.addEventListener(MouseEvent.CLICK, checkCards);
_secondCard.addEventListener(MouseEvent.CLICK, checkCards);
_firstCard = _secondCard = undefined;
mouseChildren = true;
}