我需要在textArea中获取插入符号的XY位置。
我已经找到了获得Y的方法,但我不知道如何获得X,任何人都可以帮忙吗?
如果有人想知道,这就是我得到Y的方式:
var textBeforeCaret:String = text.substr(0, caretIndex);
var textDump:String = this.text;
this.text = textBeforeCaret;
this.validateNow();
yVariable = this.textHeight;
this.text = textDump;
答案 0 :(得分: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;
}
它不是完美的,但它对我来说足够好