Solved

Esc key - Keyboard event in Actionscript 3

Posted on 2009-07-16
5
6,245 Views
Last Modified: 2013-11-11
I am trying to associate an action to Escape-key event in AS3 using the following code.
The problem is that the event is triggered (rather 'pressed escape' is printed) only when I press Shift+Escape and not just Escape.
I want it to work with just Escape key.

I would greatly appreciate if anyone can point me to the mistake I am making. Thanks.
stage.addEventListener(KeyboardEvent.KEY_DOWN, KeyPressed);

function KeyPressed(evnt:KeyboardEvent){

	switch (evnt.keyCode) {

	case Keyboard.ESCAPE :

	trace("pressed escape")

	break;

	case Keyboard.RIGHT :

	trace("RIGHT");

	break;

	case Keyboard.LEFT :

	trace("LEFT");

	break;

	}

}

Open in new window

0
Comment
Question by:whatisittellme
  • 2
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
TheDauntless earned 500 total points
ID: 24877564
You're probably testing in Flash? If you check "Control -> Disable Keyboard Shortcuts" it should work. (It should also work right away in your browser)
0
 
LVL 2

Author Closing Comment

by:whatisittellme
ID: 31604331
I was testing it in flash. I need it to run in a browser when it is finally complete. Thanks for your help. I dint realize that it is working in a browser already !
0
 

Expert Comment

by:Nakul
ID: 24959137
Hi!!
Are you talking about the Control menu??  I am not finding the option "Disable keyboard shortcuts" there.
Where to find this option.  Please clarify.
Thanks in advance.
0
 
LVL 6

Expert Comment

by:TheDauntless
ID: 24959396
It's in the control menu of the Flash player playing your SWF, not Flash's Control menu.

So in flash, run your movie (ctrl + enter) and THEN look for 'Disable Keyboard shortcuts' in the Control menu.
0
 

Expert Comment

by:Nakul
ID: 24960243
oh!! cool!!
got it now..
thanks dauntless
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now