Limiting Text to spark textarea available size
I'm trying to build a dynamically sized spark textArea which limits the possible text to its size.
E.g the textarea is set to width="300" and height="100". Now the user should only be able to enter or paste as much text as can be visible in the component. I don't want the textArea to scroll or linebrea开发者_如何学编程k if more text is entered.
I tried all sorts of approaches, but none with success.
Help is highly appreciated!
I encountered the same issue but no perfect solution is found. But I found a simple workaround for this issue.
Spark TextArea has a textDisplay attribute of type IEditableText. by default, a RichEditableText component is assigned to this attribute. There is a property called contentHeight in this component. I used this property to determine if the text height exceeds textArea height. So my simple solution is like this:
protected function textArea1_changeHandler(event:TextOperationEvent):void {
if (textArea1.textDisplay is RichEditableText){
if ((textArea1.textDisplay as RichEditableText).contentHeight > textArea1.height){
textArea1.maxChars = textArea1.text.length;
}
else {
textArea1.maxChars = 0;
}
}
}
Of cause, this needs to be fine tuned before using in an application. But I wanted to post the solution as soon as possible :) I will post exact logic required. But I think you can do it by your own too...
for a Spark textArea I used this on each change of text:
while (textArea.textFlow.flowComposer.numLines>textArea.heightInLines) textArea.text = textArea.text.substr(0,textArea.text.length-1);
精彩评论