Believe it or not, this is actually not trivial. Instead of getting text height from TextArea.textHeight, retrieving from TextArea.textField.textHeight works. Also note validateNow() before TextArea.textField.textHeight.
<?xml version="1.0" encoding="utf-8"?> <mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init();" horizontalScrollPolicy="off" verticalScrollPolicy="off" > <mx:Script> <![CDATA[ private function init():void { this.height = this.textField.textHeight + this.textField.getLineMetrics(0).height; } override public function set text(val:String):void { textField.text = val; validateNow(); //set height to the height of the text + 1 line height = textField.textHeight + textField.getLineMetrics(0).height; } ]]> </mx:Script> </mx:TextArea>
Thank you! I’ve spent the last seven hours trying to find a fix for this.
Glad it helps!
awesome
I think you don’t really need to override the set text function, you can just write validateNow() in init() before adjusting the height
You dont really need to override the function. To get the text height of any textarea all u need to do is
textArea.getTextField().textHeight
For all you guys working on textArea, getTextField() is god sent!!!
You can do anything and everything using getTextField()
Man… thanks a lot for the tip! Saved me some hours of work.
Big cheers from Brazil!
Hey, I m getting following error on line 15 above.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I debugged and found out that the textField is not instantiated. I used this.mx_internal::getTextField() to get the text field also but to avail no success.
Any hints..?
Dude, it’s years since you posted this but after 5 hours of bashing my head against the wall, this solution is a life saver. Huge thanks!