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

Posted on 2007-10-02
Last Modified: 2008-01-09
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
Question by:SatelliteCreative
    LVL 10

    Accepted Solution

    I don't think the textfield produces this event - try onChanged()

    I think that event belongs to the Key class.
    LVL 10

    Expert Comment

    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)
    LVL 3

    Author Comment

    good man sir! thanks a lot.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
    In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
    In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
    The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now