Skip to main content
Participating Frequently
February 4, 2010
Question

Get immediate text focus in TLF

  • February 4, 2010
  • 3 replies
  • 1499 views

Hi there I would be very grateful for any help regarding this quite peculiar thing I am seeing in the TLF.
Basically, what we would like to achieve is set out a TextFlow that may or not have content imported at the point of initialisation.
The problem is that the textflow will not accept focus in the sense that the user can start typing straight away but must click the sprite holding the textflow. At first I thought that this was because maybe focus could not be achieved until the flow had finished composing. So I added the CompositionCompleteEvent event and had a event handler on that waiting for it to be ready and grabbing selection using

_textFlow.interactionManager.selectRange( 0 , 0 );
_textFlow.interactionManager.setFocus();

Again no dice. So then I tried using a timer to call the same code after a second. Again no luck; the textflow will not respond to keyboard input.
If I place a button in the app and have that call the code above that works fine.I can't realistically expect people to press a button to start using the text editor , they might as well type on the screen for that.
Anybody encountered this problem before? Am I missing something obvious? Thanks in advance, you're normally excellent at giving answers. G

This topic has been closed for replies.

3 replies

Aaronius9er9er
Inspiring
April 21, 2010

Ah, got it.

Doesn't work:

textFlow.interactionManager.setFocus();

textFlow.interactionManager.selectRange(0, 0);

Does work:

textFlow.interactionManager.selectRange(0, 0);
textFlow.interactionManager.setFocus();

It seems ridonculous that that's the case, but whatever.

Adobe Employee
April 21, 2010

I think this caused by the check in SelectionManager.setFocus -- setFocus is being ignored if there is

no selection. We could change this for the next version so that if you call setFocus when the selection is not set (-1, -1),

it sets the selection to (0, 0) and then does the setFocus. That would fix this problem. It would change the behavior slightly: for instance, tabbing between text fields would set the selection where it doesn't now. This might be an improvement for many use cases, are there any that would be adversely affected if we made this change?

Aaronius9er9er
Inspiring
April 21, 2010

It seems like that would be the preferred solution.  I can't think of any adverse effects personally, but maybe someone reading this has thought of a scenario or two.

Aaronius9er9er
Inspiring
April 21, 2010

I'm trying to figure out the same thing.  Although I respect offering callLater as a possible solution, in the end it seems like a cop-out.

Adobe Employee
February 7, 2010

Is your application a Flex app? I think you can solve this problem by adding this call to your initialization sequence:

     callLater(doFocus);

And then add a "doFocus" function that calls setFocus on the textFlow:
     textFlow.interactionManager.setFocus();l
Hope this helps,
- robin