keylistener doesn't work before textfield has got focus

Posted on 2006-05-15
Last Modified: 2008-02-20
I have a flash movie with a keylistener on the Enter key.

But initially when loading the flash movie, the keylistener doesn't work.
Only when a textfield have had focus - the keylistener start working.

I have tried putting a 'Selection.setfocus("myTextField"); in the beginning of the actionscript - but that doesn't help.

Is there a enable the keylistener in another way.
Question by:sotea
    LVL 17

    Expert Comment

    You can have an idea from following solution.

    BR Dushan
    LVL 34

    Accepted Solution

    here is the code to listen enter key press;

    var myListener = new Object();
    myListener.onKeyDown = function()
          if (Key.getCode()==Key.ENTER)
                trace("enter pressed");


    IMPORTANT: to test this code you must have to disable the Keyboard shortcuts
    do the following to disable it

    after pressing ctrl+enter...
    click the "control" menu on running swf menu, and click the "disable keyboard shortcuts" option from the menu

    now you can test that enter will be tracable globally....



    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
    Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
    The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
    This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

    734 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

    24 Experts available now in Live!

    Get 1:1 Help Now