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);

1 Response to “TextField.setSelection without clicking”


  1. 1 AlexG

    Nice feature. I didnt think about setting the focus to select the text.
    Thanks

Leave a Reply

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.