0

使用 flash pro 在虚拟键盘上工作,我有点卡住了。我有一种控制克拉的方法,因此您可以滚动浏览文本字段,但我希望能够准确地在克拉使用代码的位置打入字母。

下面是我的键盘控件

// keyboard controls
for (var i=0; i<lettersSmall.length; i++)
{
    this["key_" + lettersSmall.charAt(i)].addEventListener(MouseEvent.MOUSE_UP,_keys);
    letterButtonSmall["key_" + lettersSmall.charAt(i)] = lettersSmall.charAt(i);
    letterButtonCaps["key_" + lettersSmall.charAt(i)] = lettersCaps.charAt(i);
}



function _keys(event:MouseEvent):void
{
    curTextPos = textSelect.caretIndex;
    strehrows3();
    stage.focus = textSelect;

    textSelect.setSelection(curTextPos,curTextPos);
    if (electoff.currentFrame == 2)
    {
        ajWidth(event);
    }
    if (terminalinput.currentFrame == 2)
    {
        TrWidth(null);
    }
    if (control == "on" && menu1.visible == false )
    {
        if (! shift)
        {
            textSelect.appendText(letterButtonSmall[event.target.name]);
            inputMaxWidth = textSelect.width;
        }
        else
        {
            textSelect.appendText(letterButtonCaps[event.target.name]);

            shift = false;
            inputMaxWidth = textSelect.width;
        }
        savedTxt = textSelect.text;
        textSelect.setSelection(textSelect.length,textSelect.length);
        if (textSelect.width <= 134.05)
        {
            //textSelect.autoSize = TextFieldAutoSize.LEFT;
            textSelect.x = 1.2;
        }
        if (textSelect.width >= 134.05)
        {
            //textSelect.autoSize = TextFieldAutoSize.LEFT;
            textSelect.x =  1.2-(textSelect.width-134.05);
        }
    }
    textSelect.setSelection(textSelect.length,textSelect.length);
    if (electoff.currentFrame == 2)
    {
        ajWidth(event);
    }
    if (terminalinput.currentFrame == 2)
    {
        TrWidth(null);
    }

    focuser();
    strehrows3();
    _fontSize();
    textSelect.width = inputMaxWidth;
}
4

1 回答 1

0

你可以这样做:

var inputStr:String = event.target.name; //This looks like it's value of your key pressed?
var caret:int = textSelect.textField.caretIndex;
var afterCaretText:String = textSelect.text.substr(caret);
var beforeCaretText:String = textSelect.text.substr(0,caret);

textSelect.text = beforeCaretText + inputStr + afterCaretText;

您可以在一行中完成所有这些操作,而无需创建四个变量,但我认为这样更容易理解发生了什么。

于 2013-05-10T17:56:52.200 回答