/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
package { import flash.display.*; import flash.events.*; import flash.text.*; public class Main extends Sprite { private var _inputfield:TextField; public function Main() { _inputfield = new TextField( ); _inputfield.addEventListener(Event.CHANGE, changeListener); _inputfield.width = 150; _inputfield.height = 30; _inputfield.border = true; _inputfield.background = true; _inputfield.type = TextFieldType.INPUT; addChild(_inputfield); } private function changeListener (e:Event):void { var formTextField : TextField = TextField( evtObj.target ); var wordsArr:Array = formTextField.text.split(" "); if(wordsArr.length == MAX_WORDS) { formTextField.maxChars = formTextField.text.length; } } } }