views:

1769

answers:

6

I have an app where I am looking to make the enter key act like a tab key. I can easily capture the keypress event and setFocus to a textinput field. The problem is figuring out which textinput field to give focus to. I have this code


trace(this.window.focusManager);
//returns TheWindow86.focusManager

trace(this.window.focusManager.getNextFocusManagerComponent());
//returns null

//This is what I was hoping would work
this.window.focusManager.getNextFocusManagerComponent().setFocus();

The code is in a controller class and "this.window" references an instance of a nativeWindow mxml file "TheWindow.mxml". The first trace works as expected, but the second one gives null. The last line is the code that I am wanting to work.

A: 

Hello,

Can you try with:

this.window.focusManager.setFocus(this.window.focusManager.getNextFocusManagerComponent());

Hope it works... if not let me know and I will try it in flex builder!

Adrian


My Blog on FLEX

Adrian Pirvulescu
Same error as before.TypeError: Error #1009: Cannot access a property or method of a null object reference.
Kevin
A: 

focusManager.moveFocus(FocusRequestDirection.FORWARD);

try it;

That is one I hadn't tried. Still get the same error though.TypeError: Error #1009: Cannot access a property or method of a null object reference.
Kevin
A: 

I've got the same problem. It's clear that - this.window.focusManager.getNextFocusManagerComponent().setFocus(); - gives to you en error because - this.window.focusManager.getNextFocusManagerComponent() - returns null.

I can't realize why focusManager doesn't know what component would come next... there is the problem.

That is the conclusion I have come to. The focusManager acts like it doesn't know the order of the components.
Kevin
A: 
focusManager.moveFocus(mx.events.FocusRequestDirection.FORWARD);

works well if focusManager is a property of mx.core.Application

Eugene S.B.
A: 

It seems to be a bug. I have observed it occurs around forms with defaultButtons set.

Srirangan
A: 

moveFocus works nice, thanks

wiibart