tags:

views:

19

answers:

2

When showing the html I would need to know the height of the text box in order to align things below it properly.

A: 

In order to pass it html and have it rendered as such you would set the htmlText property instead of the text property. Once the text box has been added to the display list you can get it's height just like normal.

invertedSpear
A: 

If you are trying to get the value of the height and width immediately after setting insance.htmlText, you are not going to get the calculated size of the container. You can add an event listener for FlexEvent.UPDATE_COMPLETE or force validation to do it synchronously and use getExplicitOrMeasuredHeight(). Be careful when forcing validation, it is expensive and does not necessarily need to be done in most cases. I've included a right and wrong way of making it synchronous that was not entirely obvious to me at first.

Wrong:

    var container : Box = new Box;
    var text : Text = new Text;
    container.addChild(text);
    text.htmlText = "<b>THIS IS A TEST</b>";
    trace( text.getExplicitOrMeasuredHeight() > 0 ) // False

Right:

    var container : Box = new Box;
    var text : Text = new Text;
    container.addChild(text);
    text.htmlText = "<b>THIS IS A TEST</b>";
    text.validateNow(); // Forces the validation methods to run and update the component
    trace( text.getExplicitOrMeasuredHeight() > 0 ) // True
jooks