Create a MXML Component based on TextArea & this component code will be

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:TextArea xmlns:mx=”http://www.adobe.com/2006/mxml”&gt;
<mx:Script>
<![CDATA[

private var _autoResizable:Boolean = false;

[Bindable(event=”changeAutoResize”)]
public function get autoResize():Boolean
{
return _autoResizable;
}

public function set autoResize(b:Boolean):void
{
_autoResizable = b;
if (this.mx_internal::getTextField() != null &&
_autoResizable == true)
resizeTextArea();
dispatchEvent(new Event(“changeAutoResize”));
}

override public function set text(value:String):void
{
super.text = value;
if (_autoResizable)
resizeTextArea();
}

override public function set htmlText(value:String):void
{
super.htmlText = value;
if (_autoResizable)
resizeTextArea();
}

private function resizeTextArea():void
{
var totalHeight:uint = 10;
this.validateNow();
var wi:Number = this.width;
var noOfLines:int = this.mx_internal::getTextField().numLines;
for (var i:int = 0; i < noOfLines; i++)
{
var textLineHeight:int =
this.mx_internal::getTextField().getLineMetrics(i).height;
totalHeight += textLineHeight;
}
this.height = totalHeight;
}
]]>
</mx:Script>
</mx:TextArea>

Advertisements