all groups > flash actionscript > february 2004 >
You're in the

flash actionscript

group:

Setting caret position within a text area



Setting caret position within a text area mikejan
2/11/2004 8:44:31 PM
flash actionscript: Is there any convenient way to do this? I can find where the cursor is by
using Selection.getCaretIndex(), and I can set a selection within an area by
using Selection.setSelection(), but I can't seem to find how to move the cursor
to a specific point within the text. Basically, I want to give the user the
ability to enter some text, click on a button or a dropdown that will modify
the TextFormat associated with the text area, and set focus right back on the
text component to allow them to continue typing

Incidentally, that brings me to my second problem. I've got a text field
instance called main_txt, and a toggle button called underline_btn. When the
user clicks on underline_btn, I modify the new text format associated with
main_txt to toggle underlined text. When the user clicks on the button,
main_txt loses focus. When the user click on main_txt again after toggling
underline_btn, anything they type will show the modified TextFormat. This is
as expected. However, if I include the call
Selection.setFocus(_root.main_txt); within the body of my onPress event handler
associated with underline_btn, not only does focus not shift correctly to
main_txt, but the TextFormat changes don't appear to be reflected

Any insight into what's going on with either problem would be much appreciated

-Mik

Re: Setting caret position within a text area emmquadrat
2/13/2004 9:40:04 PM
I solved the carret placing problem with just setting both params for
Selection.setSelection at the same value

Selection.setSelection(desiredPosition, desiredPosition)

It didn't always work at first time. Had to write an interval, with just one
millisecond delay. It worked propperly then.

changeCarretInterval = setInterval(changeCarret,1
function changeCarret()
Selection.setSelection ([position], [position])
clearInterval (changeCarretInterval);

AddThis Social Bookmark Button