TextField textWidth is invalid ActionScript 3

I have a dynamic textField using a postscript font (using the Classic font engine in CS5). I created textField during author. When I try to determine the actual width of a text field using the textField.textWidth property, the returned width is extremely wrong. For example, the text displayed on the screen has an approximate width of 350 pixels. but the return width is only 150 pixels. I tried switching fonts and using TextLineMetrix to no avail.

Any ideas why I am not getting the exact width?

+3
source share
3 answers

, autoSize , , , . - ...

myTextField.autoSize = TextFieldAutoSize.LEFT;
trace(myTextField.textWidth);
+9

, getBounds :

var bounds:Rectangle = textfield.getBounds(textfield.parent);
+2
var str:String = "hello world";
mytf.autoSize = true;
mytf.text = str;
trace(mytf.textWidth )
trace (mytf._width)

62 and 63.8

Strange: S

0
source

Source: https://habr.com/ru/post/1792085/


All Articles