• 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:

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

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
0
SatelliteCreative
Asked:
SatelliteCreative
  • 2
1 Solution
 
najhCommented:
I don't think the textfield produces this event - try onChanged()

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

stop();

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

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

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