Mar 09
下面的例子展示了如何通过监听TextArea的textInput事件和检查TextEvent对象的text属性,来截获该控件中按下的回车换行。
下面是具体的源代码:
Download: main.mxml
- <!-- http://blog.flexexamples.com/2008/03/07/preventing-line-feeds-in-a-textarea-control-in-flex/ -->
- <mx:application xmlns:mx="http://www.adobe.com/2006/mxml">
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white"></mx:application>
- <mx:script>
- <!--[CDATA[
- private function textArea_textInput(evt:TextEvent):void {
- if (evt.text == "\n") {
- evt.preventDefault();
- }
- }
- ]]-->
- </mx:script>
- <mx:textarea id="textArea">
- verticalScrollPolicy="on"
- width="160"
- height="120"
- textInput="textArea_textInput(event);">
- <mx:text>The quick brown fox jumped over the lazy dog.</mx:text>
- </mx:textarea>
下面是执行实例:
原文作者:Peter deHaan 翻译:minidxer

March 11th, 2008 at 5:05 pm
为什么呢,直接监听不行么?
TextInputのEventsのリスト
Event Summary Defined By
change Dispatched when text in the TextInput control changes through user input. TextInput
dataChange Dispatched when the data property changes. TextInput
enter Dispatched when the user presses the Enter key. TextInput
textInput Dispatched when the user types, deletes, or pastes text into the control. TextInput