Try using setInterval to delay the setSelection() call by a millisecond
to perform the carat positioning after flash automatically selects the
complete text when you press the tab key.
The following code positions the cursor at the end of the text string
when you tab to a textfield.
// start
var tf:TextField;
for (var i:Number = 0; i<5; i++) {
this.createTextField("field"+i+"_txt", i, 10, i*25, 200, 20);
tf = this["field"+i+"_txt"];
tf.text = "this is my text";
tf.type = "input";
tf.border = true;
tf.tabEnabled = true;
tf.tabIndex = i;
}
var listener:Object = new Object();
listener.onSetFocus = function(oldFocus, newFocus) {
this.setSel = function() {
clearInterval(this.intervalid);
var tf:TextField = eval(Selection.getFocus());
var end:Number = tf.text.length;
Selection.setSelection(end, end);
// or the front of the string
//Selection.setSelection(0, 0);
};
this.intervalid = setInterval(this, "setSel", 1);
};
Selection.addListener(listener);
// end
James O'Reilly — Consultant
Adobe Certified Flash Expert
http://www.jamesor.com
Design • Code • Train
Chris Velevitch wrote:
How to I set the position of the caret when entering or clicking in a
non-empty TextField.
I've tried:-
var field1:TextField;
var field2:TextField;
function onSetFocus():Void {
trace(this+" b="+Selection.getCaretIndex());
Selection.setSelection(0,0);
trace(this+" a="+Selection.getCaretIndex());
}
field1.onSetFocus = onSetFocus;
field2.onSetFocus = onSetFocus;
but it isn't working as expected. When I tab into a field, the whole
content is selected the caret index is -1 before and after I change
the position. When I click in the field, the caret stays at the
position clicked and the caret index is 0 before and after I change
the position.
What am I doing wrong?
Chris
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com