In flex, make all buttons be pressed with return key
Buttons in flex can be pressed with the space key, but a client would like to press enter instead of space. This can be ach开发者_如何转开发ieved by programming each button, but it would be very time consuming.
Does anyone have an idea how to do this in the less amount of time?
thanks.
I created a KeyPressForwarder
that "forwards" the key press as a click:
package com.sophware.backend
{
import flash.events.IEventDispatcher;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
public class KeyPressForwarder
{
public function dispatchAsClickEvent(evt:KeyboardEvent):void
{
if(evt.keyCode == Keyboard.ENTER)
{
var dispatcher:IEventDispatcher = evt.target as IEventDispatcher;
dispatcher.dispatchEvent(new MouseEvent(MouseEvent.CLICK));
}
}
}
}
And then setup a binding:
<mx:Button
id="Name"
keyUp="_keyPressForwarder.dispatchAsClickEvent(event)"
click="addOrModifyEntry(event)"
/>
You could eliminate the class and just use the function as the concept is generic. Just make sure you have a click
handler to handle the forwarded event.
精彩评论