1

我需要在 textArea 中获取插入符号的 XY 位置。

我已经找到了获得Y的方法,但我不知道如何获得X,有人可以帮忙吗?

如果any1想知道,这就是我得到Y的方式:

var textBeforeCaret:String = text.substr(0, caretIndex);
var textDump:String = this.text;
this.text = textBeforeCaret;
this.validateNow();
yVariable = this.textHeight;
this.text = textDump;
4

1 回答 1

0

在检查了 RafH 的链接后,我这样做了:

var popUpX:int = 0;
var popUpY:int = 0;
if(text.length > 0){

if(caretIndex > 0){
                                if(this.textField.getCharBoundaries(caretIndex -1) != null){
popUpX = this.textField.getCharBoundaries(caretIndex - 1).right;
popUpY = this.textField.getCharBoundaries(caretIndex - 1).bottom;
}
else{
popUpX = 0;
var i:int = 2;
                                    while(this.textField.getCharBoundaries(caretIndex - i) == null && caretIndex - i > -1){
i++;
}
if(caretIndex - i > -1){
popUpY = this.textField.getCharBoundaries(caretIndex - i).bottom + i * 10;
}
else{
popUpY = i * 10;
}
}
}
else{
popUpX = this.textField.getCharBoundaries(caretIndex).right;
popUpY = this.textField.getCharBoundaries(caretIndex).bottom;
}
}
else{
popUpX = 0;
popUpY = 0;
}

它并不完美,但对我来说已经足够了

于 2013-05-16T08:27:17.073 回答