Contact ZenDuo


Actionscript 2 key listener

A simple and effective way of attaching a listener to a flash document. Great for using keyboard presses to perform actions on a website. The example below can be used to call a function when the user hits the enter key on their keyboard.

keyListener = new Object();
keyListener.onKeyDown = function() {
if (Key.getCode() == Key.ENTER){
trace('you just hit the enter button')
}
};
Key.addListener(keyListener);

Tags: ,

This entry was posted on Tuesday, February 23rd, 2010 at 1:21 pm and is filed under ActionScript & Flash. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Actionscript 2 key listener”

  1. Jamie Shepherd said: February 25, 2010 at 11:29 pm

    That’s actually very useful! Thanks Mr. Bourne.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>