Tag Archive for 'hack'

TextField.setSelection without clicking

If you want to select a certain part of a textfield you use TextField.setSelection. This will only work however if you put it inside a click handler of the textfield.

Why? Because when you click on your textfield it receives focus, which is necessary for setSelection to work.

Solution? First assign focus to the textfield manually and then call setSelection:

stage.focus = tf;
tf.setSelection(0, 5);