开发者

textField textWidth is incorrect ActionScript 3

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜