我只是想阻止用户在 TextArea 中输入回车。我一直在试验 TextArea 中的“限制”属性,但似乎无法解决。
我有以下代码:
<mx:Canvas id="cvs1" label="Panel 1" width="100%" height="100%" creationComplete"addEvtListnerOnPlaceText()" backgroundColor="#FFFFFF">
<mx:TextArea id="txtP1T1" x="10" y="176" text="{placeName}" width="210" textAlign="center" color="#DC0000" restrict="this is where I need some help"/>
</mx:Canvas>
我不确定限制属性是否会涵盖这一点,但任何帮助将不胜感激。
我现在设法让一些工作:
private function addEvtListnerOnPlaceText():void{
txtP1T1.addEventListener(KeyboardEvent.KEY_DOWN, onKeyEventDown);
txtP1T1.addEventListener(KeyboardEvent.KEY_UP, onKeyEventUp);
}
[Bindable]
public var tempString:String;
private function onKeyEventDown(e:KeyboardEvent):void
{
var character:String = String.fromCharCode(e.charCode);
if (e.keyCode == 13)
{
tempString = txtP1T1.text;
KeyboardEvent.KEY_UP;
}
}
private function onKeyEventUp(e:KeyboardEvent):void
{
var character:String = String.fromCharCode(e.charCode);
if (e.keyCode == 13)
{
txtP1T1.text = tempString;
}
}
现在唯一的问题是,如果你按住回车,它会清除第一个回车,然后只要你按住它就会继续添加。我需要一种方法来阻止这种情况的发生,而不会失去对文本区域的关注。