0

我试图在文本框中捕获 1 个字母,但是当我输入多个字母时,flash 只会注册,所以如果我输入“G”它不起作用,但如果我输入“GH”那么它会注册。到目前为止,我正在像这样捕捉它。(部分代码)

function goToFrame8(event:MouseEvent):void
{

    addChild(answerInput);
    answerInput.x = 350;
    answerInput.y = 350;


    //next 'frame' button
    addChild(next8);
    next8.x = 650;
    next8.y = 520;
    next8.addEventListener(MouseEvent.CLICK, goToFrame9);


    answerInput.randomText.addEventListener(TextEvent.TEXT_INPUT, inputEventCapture);
}


function inputEventCapture(event:TextEvent):void
{
    text1 = answerInput.randomText.text;
}

function goToFrame9(event:MouseEvent):void
{
    trace(text1);
removeChild(answerInput);
}
4

1 回答 1

1

尝试使用KeyboardEvent.KEY_UP事件而不是TextEvent.TEXT_INPUT. KEY_UP 事件在按键被按下然后释放后触发。您添加事件侦听器的对象将需要焦点,但您的文本字段将具有焦点,因为您必须单击文本字段才能在其中键入。

function goToFrame8(event:MouseEvent):void
{

    addChild(answerInput);
    answerInput.x = 350;
    answerInput.y = 350;


    //next 'frame' button
    addChild(next8);
    next8.x = 650;
    next8.y = 520;
    next8.addEventListener(MouseEvent.CLICK, goToFrame9);


    answerInput.randomText.addEventListener(KeyboardEvent.KEY_UP, inputEventCapture);
}


function inputEventCapture(event:KeyboardEvent):void
{
    text1 = answerInput.randomText.text;
}

function goToFrame9(event:MouseEvent):void
{
    trace(text1);
    removeChild(answerInput);
}
于 2013-04-11T21:39:03.377 回答