On Key Press troubles

I need a function in ActionScript that will allow me to press enter and make an instance of an object visible. This will not be attached to a movie clip or a button instance, as Macromedia seems to require. How do I do this?
Ten90GroupAsked:
Who is Participating?
 
oddhoursCommented:
try this (courtesy of http://www.actionscript4designers.com/wmg3/input_text_enter_key.html):

/*** listening for the Enter/Return key ***/
keyListener = new Object();       // establish listener (generic) object

keyListener.onKeyUp = function () {        // when keyboard key released
    // take action
                                     // display code of last key pressed
    code_txt.text = Key.getCode().toString();
                                      // if Enter/Return key was pressed
    if (Key.getCode() == Key.ENTER) {        trace("ENTER key pressed");    }
}
 
Key.addListener(keyListener);      // register object to receive onKeyUp
0
 
Dushan De SilvaTechnology ArchitectCommented:
on(keyPress "<enter>"){
instance1.visible= true;
}


BR Dushan
0
 
Ten90GroupAuthor Commented:
That returns the following error upon debugging:


Mouse events are permitted only for button instances on(keyPress "<Enter>"){
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Dushan De SilvaTechnology ArchitectCommented:
Create a button. And put action script on it. Then hide it. (Alpha=0, or Visible=false..)

BR Dushan
0
 
Ten90GroupAuthor Commented:
This does not work. I hit enter, and nothing happens.
0
 
Ten90GroupAuthor Commented:
If this would work better for you, may I have your AIM or Yahoo screen name? I need this resolved ASAP for a client. Thanks.
0
 
Ten90GroupAuthor Commented:
OK, here is my issue now. It seems that this function works for every key EXCEPT enter. I have tried typing <Enter>, <enter>, and <ENTER> and none work. Is there maybe a disabled setting somewhere?
0
 
Ten90GroupAuthor Commented:
This does not work, oddhours. It is as if Flash does not like the enter key at all.
0
 
Ten90GroupAuthor Commented:
This did work for other keys, such as the LEFT key.
0
 
oddhoursCommented:
you can replace the code:
trace("ENTER key pressed");    

with whatever you like for example:

instanceNameToShow_mc._visible = true;
0
 
Dushan De SilvaTechnology ArchitectCommented:
my messenger ID is same in my profile's email address. But now I'm in home. I will at office after one hour.

BR Dushan
0
 
Ten90GroupAuthor Commented:
OK, heres the deal.
I tried oddhours' method, and it did not work. I then started searching for settings which would enable the enter key. I found a setting in the Publish Preview window called Disable Keyboard Shortcuts, located under Control. When this option is checked, the Enter key works. Only problem is now how do I make sure that this setting is included in the Publish settings?
0
 
Ten90GroupAuthor Commented:
Woo hoo! Problem fixed! Thanks everyone for your help!
0
 
oddhoursCommented:
Congrats!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.