Simulate Tab Key Pressed on Flex?

2019-04-16 17:17发布

问题:

It is possible to Simulate a Tab Key when another key is pressed? I'm looking to do exactly the same, but with the DOWN & ENTER Key.

I know about the onKeyDown function. I'm trying this but it doesn't work.

private function onKeyDown( e:KeyboardEvent ) :void
            {
                if( e.keyCode == Keyboard.DOWN )
                {
                    (e.currentTarget as TextInput).dispatchEvent(new KeyboardEvent(KeyboardEvent.KEY_DOWN, true, false, 0, Keyboard.TAB));
                }
            }

I know tab works differently, I saw it in Here but still not idea.

Any help would be appreciated.

Thanks in advance.

回答1:

I resolved it like this. Hope this helps somebody else later.

private function onKeyDown( e:KeyboardEvent ) :void
            {
                if( e.keyCode == Keyboard.DOWN || e.keyCode == Keyboard.ENTER)
                {                   
                    focusManager.getNextFocusManagerComponent().setFocus();

                }
                if(e.keyCode == Keyboard.UP)
                {
                    focusManager.getNextFocusManagerComponent(true).setFocus();
                }
            }

In Flash, focusManager by itself may be undefined in that context. Change to: evt.currentTarget.focusManager.getNextFocusManagerComponent().setFocus();



回答2:

Try to put tabbing component in array, then change focus manually with:

stage.focus = myComp;

or

stage.focus = myComps[currentCompOrderNumber+1];