2010-11-03 84 views
0

我正在处理一个Spark TextArea作为文本输入(通过设置heightInLines =“1”)。 TextArea是mxml组件的一部分,我想在文本更改时调整组件的大小。计算Spark TextArea宽度

我还没有能够使用textArea.measureaText(textArea.text)来获取行度量并使用它。我得到这个错误“参数antiAliasType必须是非空的。”

有没有什么办法可以获得TextArea的宽度,它将在运行时为特定的字符串或特定的TextFlow使用?

回答

0

有点丑,但对我的作品:

var uiText:UItextField = new UITextField(); 

// if you have custom text style on the TextArea then set it the same of this uitextfield 
uiText.setTextFormat("bla bla bla"); 

uiText.text = "This is the text that I want the size for"; 

var textW:Number = uiText.textWidth; 
var textH:Number = uiText.textHeight; 

// then we need to consider also the border of the text area and the paddings 
// try read the padding values and border sizes using getStyle(...) 

myTextArea.width = textW+2*borderW+paddingL+paddingR; 
myTextArea.height = textH+2*borderH+paddingT+paddingB; 

这应该是所有