StageText的问题,自动更正和限制 [英] StageText issues with autocorrect and restrict

查看:182
本文介绍了StageText的问题,自动更正和限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用StageText的在Android AIR应用程序如下:

I am attempting to use StageText in an Android AIR app as follows:

var tf:StageText = new StageText();
tf.stage = stage;
tf.viewPort = new Rectangle(0, 0, stage.fullScreenWidth, 90); 
tf.text = "Test";
tf.editable = true;
tf.autoCorrect = false;
tf.fontSize = 50;
tf.color = 0xFF0000;
tf.maxChars = 12;
tf.restrict = "A-Za-z";

在Android设备一切正常,直到你按下删除按钮编辑此StageText的。到现在为止,没有自动更正的建议将被显示,但一旦删除按钮是pressed自动更正建议,现在将开始显示出来。现在,下一个按键preSS将在光标位置,而不是什么关键你pressed(例如,如果你preSS的S,它将插入儿子,如果这是自动更正插入自动更正字建议)。

When editing this StageText on an Android device everything works as expected until you hit the delete button. Until now, no autocorrect suggestions will have been displayed, but once the delete button is pressed autocorrect suggestions will now start to be displayed. Now, the next key you press will insert the autocorrected word at the cursor position instead of whatever key you pressed (e.g. if you press "s" it will insert "Son" if that was the autocorrect suggestion).

真正奇怪的是,如果我设置限制财产StageText的这种行为只发生 - 如果我注释掉限制样样在行功能完全按照我期望的那样。

The really weird thing is that this behaviour only occurs if I set the restrict property on the StageText - if I comment out the restrict line everything functions exactly as I would expect.

推荐答案

从文档(<一href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/StageText.html#restrict"相对=nofollow> flash.text.StageText.restrict ):

请注意:限制仅适用于用户输入;脚本可以插入任何   字符在文本字段。

Note: Restrictions apply only to user input; a script can insert any characters into the text field.

由于限制而不是分配价值,不是100%可靠,文本字段的限制属性,可以评估使用自己的逻辑(的正则表达式)在更改事件处理程序。这将使你完全控制哪些用户进入到文本框。

Since restrictions are not 100% reliable, instead of assigning value to the textfield's restrict property, you could evaluate the text yourself using your own logic (RegExp) in a CHANGE event handler. This would give you full control over what users enter into the textfield.

tf.addEventListener(Event.CHANGE, textFieldChangeEventHandler);

private function textFieldChangeEventHandler(event:Event):void
{
    trace(event.target.text);
    //Manage text
}

这篇关于StageText的问题,自动更正和限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆