Posted By

adrianparr on 05/27/10


Tagged

multiline return restrict newline textarea as3 prevent linebreak carriage


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tspitzr


AS3 Prevent Multiline in TextArea Component


 / Published in: ActionScript 3
 

URL: http://stackoverflow.com/questions/1239891/as3-textarea-component-disallow-user-to-enter-a-line-break

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.

  1. import flash.text.TextFormat;
  2. import fl.controls.TextArea;
  3. import flash.events.Event;
  4.  
  5. var myTextArea:TextArea = new TextArea();
  6. myTextArea.setSize(200, 100);
  7. myTextArea.text = "Hello World";
  8.  
  9. var myTextFormat:TextFormat = new TextFormat();
  10. myTextFormat.font = "Arial";
  11. myTextFormat.size = 22;
  12. myTextFormat.bold = false;
  13. myTextFormat.italic = false;
  14. myTextFormat.underline = false;
  15. myTextArea.setStyle("textFormat", myTextFormat);
  16.  
  17. myTextArea.x = 30;
  18. myTextArea.y = 30;
  19. addChild(myTextArea);
  20.  
  21. myTextArea.setStyle("focusRectSkin",Sprite);
  22.  
  23. myTextArea.addEventListener(Event.CHANGE, onMyTextArea_CHANGE);
  24.  
  25. function onMyTextArea_CHANGE(event:Event)
  26. {
  27. myTextArea.text = myTextArea.text.replace("\r", "");
  28. }

Report this snippet  

You need to login to post a comment.