/ Published in: ActionScript 3
There is no built-in way of preventing the user pressing the Enter Key in a TextArea Component (in a standard TextField you can set multiline = false). Instead, you need to listen for the CHANGE event and then remove the Carriage Retun (\r) character.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import flash.text.TextFormat; import fl.controls.TextArea; import flash.events.Event; var myTextArea:TextArea = new TextArea(); myTextArea.setSize(200, 100); myTextArea.text = "Hello World"; var myTextFormat:TextFormat = new TextFormat(); myTextFormat.font = "Arial"; myTextFormat.size = 22; myTextFormat.bold = false; myTextFormat.italic = false; myTextFormat.underline = false; myTextArea.setStyle("textFormat", myTextFormat); myTextArea.x = 30; myTextArea.y = 30; addChild(myTextArea); myTextArea.setStyle("focusRectSkin",Sprite); myTextArea.addEventListener(Event.CHANGE, onMyTextArea_CHANGE); function onMyTextArea_CHANGE(event:Event) { myTextArea.text = myTextArea.text.replace("\r", ""); }