I seem to remember having some case where a textArea would not update it's size measurements until it was validated . I may well be wrong about this, but try :
private function onUpdateComplete(): void {
idContentText.validateNow();
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');
}
apologies if it's not actually the correct answer, but the rest of your code
looks pretty sensible to me - I'm wondering if it's being measured at the wrong
time?
-----Original Message-----
From: [email protected] on behalf of Aaron Miller
Sent: Sat 30/08/2008 20:06
To: [email protected]
Subject: [flexcoders] What is the best way to measure htmlText at run time?
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
______________________________________________________________________
This communication is from Primal Pictures Ltd., a company registered in
England and Wales with registration No. 02622298 and registered office: 4th
Floor, Tennyson House, 159-165 Great Portland Street, London, W1W 5PA, UK. VAT
registration No. 648874577.
This e-mail is confidential and may be privileged. It may be read, copied and
used only by the intended recipient. If you have received it in error, please
contact the sender immediately by return e-mail or by telephoning +44(0)20 7637
1010. Please then delete the e-mail and do not disclose its contents to any
person.
This email has been scanned for Primal Pictures by the MessageLabs Email
Security System.
______________________________________________________________________<<winmail.dat>>

