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

Can't get onKeyDown to work (CS3, AS2)

Hi, I'm having trouble getting anything to happen with a listener and key down events.

I've created a one frame flash project, set as AS2, and 'tested' in flash. The frame action is this:

var keyListener:Object = new Object();
keyListener.onKeyDown = function () {
      trace ("You pressed a key");

And on the stage is a text area set to 'input text'.

So.. uh... this should just work and trace whenever I type into the field right? What am I doing wrong? Probably easy to answer, but VERY urgent hence the points.

Cheers, Ben
  • 2
1 Solution
I don't think the textfield produces this event - try onChanged()

I think that event belongs to the Key class.
and if you want to pick up the key event regardless of whether it's in the textfield or not you could use:


var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
    trace("DOWN -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));

(from flash help file, but it's a decent example because you can just paste it in and it works)
SatelliteCreativeAuthor Commented:
good man sir! thanks a lot.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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