What did the code look like when you tried to save the last length?

From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of 
tchredeemed
Sent: Monday, November 10, 2008 6:50 AM
To: [email protected]
Subject: [flexcoders] Help with Custom Text Area (Limited by lines)


This is my code:

public class LimitedTextArea extends TextArea {

private static const MAX_LINES:int = 10;
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 );
if( tf.numLines > MAX_LINES )
limitHit = true;
}

protected override function keyUpHandler(event:KeyboardEvent):void {
if( limitHit ){
this.text = storedInput;
limitHit = false;
}
}

private function changeHandler( event:Event ):void {
if( limitHit ){
this.text = storedInput;
limitHit = false;
}
}

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

}

If I just keep entering down and typing stuff in, it works and stops
me from typing more... the problem is when I try to go back and edit
what I have typed, the limit has been hit (10 lines)... I am not sure
how to allow deleting or editing as long as it still does not go
longer than allowed...

Any ideas? ( I tried what you said Alex, but I couldn't get it to work
properly )

Reply via email to