Posted By

sidneydekoning on 08/10/09


Tagged

event input change TextField maxChars


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

mali
TrentSkunk


Restrict TextField to N Words instead of N Characters


 / Published in: ActionScript 3
 

  1. package {
  2. import flash.display.*;
  3. import flash.events.*;
  4. import flash.text.*;
  5.  
  6. public class Main extends Sprite {
  7. private var _inputfield:TextField;
  8.  
  9. public function Main() {
  10.  
  11. _inputfield = new TextField( );
  12. _inputfield.addEventListener(Event.CHANGE, changeListener);
  13. _inputfield.width = 150;
  14. _inputfield.height = 30;
  15. _inputfield.border = true;
  16. _inputfield.background = true;
  17. _inputfield.type = TextFieldType.INPUT;
  18. addChild(_inputfield);
  19.  
  20.  
  21. }
  22. private function changeListener (e:Event):void {
  23. var formTextField : TextField = TextField( evtObj.target );
  24. var wordsArr:Array = formTextField.text.split(" ");
  25.  
  26. if(wordsArr.length == MAX_WORDS) {
  27. formTextField.maxChars = formTextField.text.length;
  28. }
  29. }
  30. }
  31. }

Report this snippet  

You need to login to post a comment.