Specific Keys

2008 September 02

This is another of those things that I have seen come up several times on the flashkit forums. Someone keeps asking if there's a better way to make a key listener than having one listener with a big switch statement to decide what to do based on which key was pressed. Well, there is now.

Using this is pretty simple. Something like this

               SpecificKeys.init(stage);
               var specKeys:SpecificKeys = SpecificKeys.getInstance();
               //...
               specKeys.addEventListener(SpecificKeys.getEventID(KeyboardEvent.KEY_DOWN, "A"), hilite);
   

This adds an event listener which only triggers when the "A" key is pressed.

Here's a sample

And here's the source

privacy policy
Sponsored links