当显示html时,我需要知道文本框的高度,以便正确对齐它下面的内容。
答案 0 :(得分:0)
为了传递html并将其呈现为这样,您将设置htmlText属性而不是text属性。将文本框添加到显示列表后,您可以像平常一样获得高度。
答案 1 :(得分:0)
如果您在设置insance.htmlText后立即尝试获取高度和宽度的值,则不会获得容器的计算大小。您可以为FlexEvent.UPDATE_COMPLETE添加事件侦听器,或强制验证以同步执行它并使用getExplicitOrMeasuredHeight()。在强制验证时要小心,它很昂贵,并且在大多数情况下不一定需要完成。我已经包含了一种使其同步的正确和错误的方式,这对我来说并不是很明显。
错:
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
右:
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