PDA

View Full Version : Pushbutton Component and KeyPresses


rintrah
09-04-2003, 04:39 PM
How can one assign a keypress event to a pushbutton componenet - ie, mouseclick and enter key have the same effect.

jaybee
09-09-2003, 10:07 AM
if you have a method assigned to the pushbutton comp called myClick then put this code into yr movie:


myListener = new Object();

myListener.onKeyUp = function () {
if(Key.getCode()==13) myClick();
}
Key.addListener(myListener);


you may need to add code to the onKeyUp method to check that the button has the focus, if that's the idea you could do it like this


buttonFocus = false;
myListener = new Object();
myListener.onKeyUp = function () {
if(buttonFocus && Key.getCode()==13) myClick();
}
Key.addListener(myListener);
button_comp.onSetFocus = button_comp.onKillFocus = function() {
buttonFocus = !buttonFocus;
}