PDA

View Full Version : Trapping the Escape key



JohnLawton
October 8th, 2002, 04:06 AM
Hi

I am creating a software product demonstrator. The software uses the Escape key to let users get out of menus - crap I know, but that's the way they do it!!

My problem is that I want Flash MX to look out for the Escape key being hit within my demonstrator and then go to another frame when it is hit.

Any ideas/sample code would be very welcome

Thanks

John :)

JohnLawton
October 8th, 2002, 04:34 AM
Well, it just goes to show that a little struggle through the help files sometimes pays off!!

_root.onEnterFrame = function() {
if (key.isDown(key.ESCAPE)) {
gotoAndPlay("EscapeHit");
}
};

will do the job from that frame on. If anyone has any smarter ways of doing it please let me know.


I hope this can help someone else one day!

Cheers

John :)

pom
October 8th, 2002, 09:04 AM
:-\ It doesn't work for me. I can trap the space bar, any letter, but not escape...

Anyway, you can check if escape was pressed only when the user presses a button, it will be less processor intensive:
_root.onKeyDown = function() {
if (key.isDown(key.ESCAPE)) {
trace("EscapeHit");
}
};
Key.addListener(_root);pom :smirk: