I have a dynamic textField using a postscript font (using the Classic font engine in CS5). I created the textFie开发者_开发技巧ld at author time. When I try to determine the actual width of the textField using the textField.textWidth property, the returned width is wildly wrong. For example, the text as displayed on screen has an approximate width of 350 pixels. but the returned width is only 150 pixels. I have tried switching fonts, and using the TextLineMetrix to no avail.
Any ideas why I am not getting an accurate width?
Make sure you set the autoSize property of the text field, this will cause flash to recognize the width as the width of the text instead of the width of the containing text field. Try something like this...
myTextField.autoSize = TextFieldAutoSize.LEFT;
trace(myTextField.textWidth);
I find that getBounds give the closest results:
var bounds:Rectangle = textfield.getBounds(textfield.parent);
var str:String = "hello world";
mytf.autoSize = true;
mytf.text = str;
trace(mytf.textWidth )
trace (mytf._width)
62 and 63.8
Weird:S
精彩评论