Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

e.keyCode==Keyboard.ESCAPE not working

i am building a flash game whereby when users select a building he/she wishes to build but later changes their mind, he/she could press the "ESC" on their keyboard so that the building gets unselected - users will not be forced to build once he/she selects a building. I tried assigning ESCAPE key but it did not work. it works fine if i assign it to SPACEBAR, LEFT, RIGHT KEY etc..but it does not make sense that users have to press those keys. ESCAPE key should be the ideal. Here's my code:

import flash.events.KeyboardEvent;

stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
function myKeyDown(e:KeyboardEvent):void {
    if (e.keyCode==Keyboard.ESCAPE) {
        trace(e.keyCode);
        constructionButtonUnselected();
    }
}

Anybody knows whats preventing the system from recognizing the ESCAPE key?

like image 776
Desmond Ho Avatar asked Mar 19 '26 21:03

Desmond Ho


2 Answers

The escape key will work when a swf is running in a browser or standalone, but when you are running the content in Flash CS4 or Flash CS5, the IDE will trap the Escape key and not pass it on to the player. The same thing happens with the F# keys and a few others.

If you want to use the Escape key, you can, but you will need another key defined to use as a back up when you are working in the IDE.

like image 109
Andrew Traviss Avatar answered Mar 21 '26 11:03

Andrew Traviss


Actually, when you compile the SWF in the IDE, goto Controls -> Disable Keyboard Shortcuts, this will allow you to capture the Escape key's KeyboardEvent instead of the IDE grabbing it prematurely.

like image 31
Matt Bruce Avatar answered Mar 21 '26 10:03

Matt Bruce



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!