2013-05-07 28 views
0

早些时候,我正在努力水平移动克拉,现在我需要将它向上移动&向下文本字段。 这是一个虚拟键盘,所有的箭头控件都是用编码按钮完成的。用as3垂直控制克拉

继承人一个例子:我有一个文本字段,其中有两行文本变量,我们的克拉是在底线的末尾。我的目标是将克拉移至第一行的末尾。

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

有可能是一个更简单更优雅的方式来做到这一点,但是这是我能想到的,应该足以让你开始:(用于将插入符上)

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 
}