actionscript 3 - Action Script. How to disable keyboard? -
how disable keyboard keys in action script?
i'm creating flash "memory" game, idea discover 2 equal cards. when 2nd card discovered shown 750 milliseconds, in time player can't actions. when use mousechildren = false;
player can't click mouse time, can use keyboard arrows/enter/space/tab buttons... need disable time.
here part of code:
{ 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; }
you have functions adding/removing listeners :
function addlisteners():void { // loop through , add listeners cards // add keyboard listeners } function removelisteners():void { // loop through , remove listeners cards // remove keyboard listeners }
before set timer, remove listeners :
removelisteners();
then in flipback timer handler call addlisteners :
addlisteners();
Comments
Post a Comment