早些时候我正在努力水平移动Carat现在我需要将它向上移动&在文本字段中。 这适用于虚拟键盘,因此所有箭头控件都使用编码按钮完成。
下面是一个例子:我有一个文本字段,其中包含两行文本变量,而我们的克拉位于底线的末尾。我的目标是将克拉移动到第一行的末尾。
var boop = textSelect.text.length;
var snoop = boop;
// arrow controls to move left and right
function larw(event:MouseEvent):void
{
snoop -= 1;
stage.focus = textSelect;
textSelect.setSelection( snoop,snoop);
}
function rarw(event:MouseEvent):void
{
snoop += 1;
stage.focus = textSelect;
textSelect.setSelection( snoop,snoop);
}
// moving up
function uarw(event:MouseEvent):void
{
}
答案 0 :(得分:0)
可能有一种更简单,更优雅的方式来做到这一点,但这是我能想到的,应该足以让你开始:(为移动插入符号)
var line:int = textSelect.getLineIndexOfChar(textSelect.caretIndex); //get the current line the caret is in
//if the line isn't already at the top-most line
if(line > 0){
var charBounds:Rectangle = textSelect.getCharBoundaries(textSelect.caretIndex); //get the coordinates of the current caret position
var prevLinePos:Number = charBounds.y - textSelect.getLineMetrics(line-1).leading - (textSelect.getLineMetrics(line-1).height * .5); //the y value of the middle of the previous line
var newIndex:Number = textSelect.getCharIndexAtPoint(charBounds.x,prevLinePos); //get the character that is closest to that position
textSelect.setSelection(newIndex,newIndex); //set the caret
}