开发者

How do I enable a Text class to accept html text and will I be able to calculate height and width?

When showing the html I would need to know the hei开发者_Go百科ght of the text box in order to align things below it properly.


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜