Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetCaretIndex for cursor location = -1

Status
Not open for further replies.

TMac42

Programmer
Jul 24, 2000
83
US
I have some code that is accurately getting the blinking cursor position (ex: 2, 3, 4) using GetCaretIndex.

Right below that, I'm assigning that value to a global variable: iTestLocation. If I trace iTestLocation here, it is correct.

Later, in another function where I want to delete a character to the right of the cursor location, I reference iTestLocation and no matter what, it's always = -1. I'm using Flash 8. Can anyone please help with this??
 
Figured out my issue but still need help.

The problem is that when I click on a button to delete a character within the textbox (to the right of the cursor location), the cursor location is now -1 because I clicked outside of the text box.

Thoughts around this? How can I add conditional logic so clicks only in the text box listen for cursor location?
 
Here's one solution: "iTestLocation" is only updated when the Input Text Field (I named it as "inputText") is in focus. So even when you click on elsewhere on stage, iTestLocation retains the last known caret position of the text field.

[tt]// Main timeline
//
var iTestLocation:Number;
//
var mouseListner:Object = new Object();
mouseListner.onMouseUp = getCaretPos;
Mouse.addListener(mouseListner);
//
var keyListner:Object = new Object();
keyListner.onKeyUp = getCaretPos;
Key.addListener(keyListner);
//
function getCaretPos():Void {
if (Selection.getFocus().indexOf("inputText")>-1) {
var caretPos:Number = Selection.getCaretIndex();
if (caretPos>-1) {
iTestLocation = caretPos;
}
}
}
//[/tt]

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top