Я не нашел способа указать локаль во 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);
}
}