public class LimitedTextArea extends TextArea {

private static const MAX_LINES:int = 10;
private var textLength:int = 0;
private var storedInput:String;
private var limitHit:Boolean = false;

public function LimitedTextArea(){
this.addEventListener( KeyboardEvent.KEY_UP, keyUpHandler );
this.addEventListener( KeyboardEvent.KEY_DOWN, keyDownHandler );
this.addEventListener( Event.CHANGE, changeHandler );
}

//--------------------------------------------------
// EVENT LISTENERS
//--------------------------------------------------

protected override function keyDownHandler(event:KeyboardEvent):void {
storedInput = this.text;
var tf:TextField = TextField( this.textField );
textLength = tf.length;                 
if( tf.numLines > MAX_LINES )
limitHit = true;
}

protected override function keyUpHandler(event:KeyboardEvent):void {
var tf:TextField = TextField( this.textField );
if( limitHit && tf.length > textLength ){
this.text = storedInput;
limitHit = false;
}
}

private function changeHandler( event:Event ):void {
var tf:TextField = TextField( this.textField );
if( limitHit && tf.length > textLength ){
this.text = storedInput;
limitHit = false;
}
}

//--------------------------------------------------

}



This does work if I want to go back and change a letter to a different
letter, but I guess another problem I am having is that I want to be
able to keep typing as long as I do not go further than the line limit...

For instance, let's say I hit my limit, but I hit it like this:

a
a
a
a
a
a
a
aaaaaaaaaaaa

I should be able to go up in the first couple lines and keep typing,
because it won't push the bottom line out any further...

Reply via email to