• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 603
  • Last Modified:

close popup when 'Esc' key is pressed

hi guys
I have a popup which i am displaying using
PopUpManager.centerPopUp(dataGrid);

When the 'Esc' key is pressed, i want the popup to close. Is that possible?

thanks
0
royjayd
Asked:
royjayd
  • 2
  • 2
2 Solutions
 
dgofmanCommented:
add key event listener for stage

stage.addEventListener(KeyboardEvent.KEY_DOWN, myKeyDown);
function myKeyDown(e:KeyboardEvent):void {
    if (e.keyCode==Keyboard.ESCAPE) {
         dataGridInstance.deletePopUp();
    }
}
0
 
royjaydAuthor Commented:
couple of questions

1.when should i use KEY_UP v/s KEY_DOWN
2. In stage.addEventListener... what does 'stage' mean

thanks
0
 
dgofmanCommented:
please try my example first
0
 
royjaydAuthor Commented:
thanks it works

one question i have is
hi
Like you used
if (e.keyCode==Keyboard.ESCAPE) {

Is there a way to check if only alphabets (a-z) or numbers (0-9) is pressed ?

thanks
0
 
zzynxSoftware engineerCommented:
>> Is there a way to check if only alphabets (a-z) or numbers (0-9) is pressed ?

I think this should work

if ( ( e.keyCode>=Keyboard.A && e.keyCode<=Keyboard.Z ) ||
     ( e.keyCode>=Keyboard.NUMBER_0 && e.keyCode<=Keyboard.NUMBER_9 ) ||
     ( e.keyCode>=Keyboard.NUMPAD_0 && e.keyCode<=Keyboard.NUMPAD_9 )  ) {
  ...
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now