Flex 3:如何模拟按下的输入/返回键

时间:2011-10-11 16:47:19

标签: flex keyboard-events

标题几乎说明了一切......有一种简单的方法可以模拟按下的回车键吗?

编辑:

我有这么多,但我不知道如何让它循环运行:

var keyCode:uint = Keyboard.ENTER;
var e:KeyboardEvent = new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false, 0, keyCode);

我需要它在以下循环中运行:

for (var i:int = 0; i < changes.length; i++)
{
    if (changes[i][0] == "directorsPrep")
    {
        directorsPrep[changes[i][1]].phaseFillers[changes[i][2]].fillDisplayName.setFocus();
        // NEED IT TO RUN RIGHT HERE!
    }
}

1 个答案:

答案 0 :(得分:2)

for (var i:int = 0; i < changes.length; i++)
{
    if (changes[i][0] == "directorsPrep")
    {
        directorsPrep[changes[i][1]].phaseFillers[changes[i][2]].fillDisplayName.setFocus();
        // NEED IT TO RUN RIGHT HERE!
        // create the keyboard event; using your code
        var keyCode:uint = Keyboard.ENTER;
        var e:KeyboardEvent = new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false, 0, keyCode);
        // dispatch it    
        componentThatYouWantToDispatchKeyBoardEvent.dispatchEvent(e);
    }
}

componentThatYouWantToDispatchKeyBoardEvent变量可以是扩展EventDispatcher或实现IEventDispatcher的任何组件。