Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

New Developer
Posts: 13
Registered: ‎08-13-2008
My Device: Bold 9700
My Carrier: at&t
Accepted Solution

Set Cursor Position for TextInput

Does anyone know of a method I can call on TextInput focus which will set the cursor's position or select certain text within the input field? I'm trying to get the cursor to always start typing at the end of pre-filled text.


I've tried these but they don't seem to be valid methods for TextInput (I didn't expect them to work because they are not in the documentation, but it was worth a try):



mytxtInput.setSelection(mytxtInput.text.length, mytxtInput.text.length);


mytxtInput.selectRange(mytxtInput.text.length, mytxtInput.text.length)


Any help would be greatly appreciated! 


Thanks to everyone in this forum for all they great posts! They have really helped answer a lot of my questions.


Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: Set Cursor Position for TextInput



you have the right idea but instead of applying the setSelection method on your TextInput object, you need to apply it to the inner textField property reference to the TextField object inside.


here is a sample code from an older thread that selects all the text in a TextInput object:


import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.FocusEvent;
import flash.events.MouseEvent;

import qnx.ui.buttons.LabelButton;
import qnx.ui.text.TextInput;

public class TextInputTest extends Sprite

private var myInput:TextInput;

public function TextInputTest()

// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

myInput = new TextInput();


var newBtn:LabelButton = new LabelButton();
newBtn.label = "Click Me";
newBtn.setPosition(325, 0);

newBtn.addEventListener(MouseEvent.CLICK, selectMyText);


private function selectMyText(e:MouseEvent):void
stage.focus = myInput;
myInput.textField.setSelection(0, myInput.textField.length);


this line is where it does the trick:


myInput.textField.setSelection(0, myInput.textField.length);

the first parameter is the start selection point and the last parameter is how much of it is to be selected.


here is the link to the thread the code is from for more detail:




hope that helps. good luck!


J. Rab (Blog) (Twitter)
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
New Developer
Posts: 13
Registered: ‎08-13-2008
My Device: Bold 9700
My Carrier: at&t

Re: Set Cursor Position for TextInput

That worked great! Thank you very much!