我遇到了一个奇怪的错误与CS5教授开发的联系方式表单。我的键盘布局设置为英语(英国),按shift-2给我一个",shift-‘给我一个@在Chrome,记事本,Word等。在Flash表单的文本字段中,输入shift-2给我@,但shift-’给我“。我知道这就是美国键盘的布局,但它让我的用户感到困惑。
如何更改文本字段以使其正确适用于我的键盘布局?
发布于 2010-12-14 06:48:15
在使用wmode=“透明”或wmode=“不透明”时,有一个已知的错误,在某些浏览器(火狐和可能的Crome)中,会出现此类错误,默认为美国键盘布局。据我所知,没有好的解决方案,只有相当繁琐的变通方法。如果你搜索flash wmode键盘bug,你会发现相当多的信息和变通方法。
发布于 2010-12-14 10:53:02
我没有找到在Flash中指定语言环境的方法,但是下面的代码可以做你想要的:
package {
import flash.display.Sprite;
public class NewClass extends Sprite {
public function NewClass() {
addChild(new TextFieldReplacingChars());
}
}
}
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.TextEvent;
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.utils.Timer;
class TextFieldReplacingChars extends Sprite {
private var tf:TextField;
private var toReplace:Object;
private var str1:String = '';
private var str2:String = '';
private var pressedKeyCount: int = 0;
private var timer:Timer;
public function TextFieldReplacingChars() {
tf = new TextField();
addChild(tf);
tf.type = 'input';
tf.addEventListener(TextEvent.TEXT_INPUT, ontext);
tf.addEventListener(KeyboardEvent.KEY_DOWN, onPress);
tf.addEventListener(KeyboardEvent.KEY_UP, onRelease);
toReplace = new Object();
toReplace['"'] = '@';
toReplace['@'] = '"';
timer = new Timer(1, 1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, updateText);
}
private function onRelease(e:KeyboardEvent):void {
pressedKeyCount -= pressedKeyCount > 0 ? 1 : 0;
}
private function onPress(e:KeyboardEvent):void {
pressedKeyCount += toReplace[String.fromCharCode(e.charCode)] ? 1 : 0;
}
private function ontext(e:TextEvent):void {
if (toReplace[e.text] && pressedKeyCount > 0) {
str1 = tf.text.substring(0, tf.caretIndex) + toReplace[e.text];
str2 = tf.text.substring(tf.caretIndex, tf.text.length);
timer.start();
}
}
private function updateText(e:TimerEvent):void {
tf.text = str1 + str2;
tf.setSelection(str1.length, str1.length);
}
}https://stackoverflow.com/questions/4433956
复制相似问题