0

早些时候,我一直在努力水平移动克拉,现在我需要在文本字段中上下移动它。这适用于虚拟键盘,因此所有箭头控件都使用编码按钮完成。

下面是一个示例:我有一个文本字段,其中有两行不同数量的文本,我们的克拉位于底线的末尾。我的目标是将克拉移动到第一行的末尾。

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
{

}
4

1 回答 1

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
}
于 2013-05-07T21:17:21.617 回答