Hello,

I have to create Text components at run time and assign some content to it's
htmlText. I'm trying to figure out the best way to measure the content's
height, but so far have not been very good at it. Ideally, I would like to
use the same method Flex uses when the Text component is explicitly set in
the MXML like so:

<mx:Text width="100%" htmlText={HTML_CONTENT} />


I've tried using the seemingly obvious measureHTMLText, but this doesn't
seem to work as I expected it to.

===========================
<?xml version="1.0" encoding="utf-8"?>
<mx:Box xmlns:mx="http://www.adobe.com/2006/mxml"; width="100%" height="100%"
>

<mx:Script>
<![CDATA[
    import mx.utils.ObjectUtil;

[Bindable]
private var _htmlContent:String;

public function get htmlContent(): String {
    return _htmlContent;
}

public function set htmlContent( data:String ): void {
    _htmlContent = data;
}

private function onUpdateComplete(): void {
    trace('HTMLContentBox.onUpdateComplete: '+_htmlContent);

    //mesure content height and update this.height accordingly
    var tm:TextLineMetrics = idContentText.measureHTMLText(_htmlContent);
    trace( ObjectUtil.toString(tm) );

    this.height = tm.height + this.getStyle('paddingBottom') +
this.getStyle('paddingTop');
}

]]>
</mx:Script>

    <mx:Text id="idContentText" width="100%" height="100%"
selectable="false" htmlText="{_htmlContent}" styleName="mediumStandardLabel"
         updateComplete="onUpdateComplete();" />
</mx:Box>
===========================


So, this leaves me with a question. What is the "official" way to measure
htmlText at run time?


Thanks for any input!
~Aaron

Reply via email to