【问题标题】:Get the XY position of the caret in TextArea获取 TextArea 中插入符号的 XY 位置
【发布时间】:2013-05-08 14:53:33
【问题描述】:

我需要在 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;

【问题讨论】:

标签: actionscript-3 apache-flex textarea flash-builder


【解决方案1】:

在检查了 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;
}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-26
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    相关资源
    最近更新 更多