开发者

In flex, make all buttons be pressed with return key

开发者 https://www.devze.com 2022-12-28 03:50 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消