Return to Snippet

Revision: 16632
at August 10, 2009 13:08 by sidneydekoning


Initial Code
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; 
		}
    }
  }
}

Initial URL

                                

Initial Description

                                

Initial Title
Restrict TextField to N Words instead of N Characters

Initial Tags
event

Initial Language
ActionScript 3