自动适应高度的TextArea,类似的可适宽度也一样。
<?xml version="1.0" encoding="utf-8"?>
<mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()"
change="changeHandler()" resize="resizeHandler()"
>
<mx:Script>
<![CDATA[
private function init():void
{
this.verticalScrollPosition = 0;
this.verticalScrollPolicy = "off";
this.textField.autoSize = TextFieldAutoSize.LEFT;
this.height = this.textField.textHeight + this.borderMetrics.top + this.borderMetrics.bottom;
}
private function changeHandler():void
{
callLater(resetHeight);
}
private function resizeHandler():void
{
callLater(resetHeight);
}
private function resetHeight():void
{
this.verticalScrollPosition = 0;
this.height = this.textField.textHeight + this.borderMetrics.top + this.borderMetrics.bottom;
}
]]>
</mx:Script>
</mx:TextArea>