Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextFieldAutoSize and textWidth in AS3 [closed]

I'm trying to draw a background to a text field in AS3.

I have a TextField with an embedded font and using autoSize = TextFieldAutoSize.LEFT. I assign the text to the TextField then call try to draw a roundedRect using the textWidth of the TextField. The text field width is always smaller than the actual text width.

Is there another way to get the actual textwidth? I did a few quick google searched but I haven't found anything.

Code:

var tfProgramName:TextField = TextUtil.createTextField(true,"Arial",20,true);
tfProgramName.width = 100;
tfProgramName.autoSize = TextFieldAutoSize.LEFT;
tfProgramName.x = 5;
tfProgramName.y = 5;
addChild(tfProgramName);

tfProgramName.text = _program.title;
background.graphics.clear();
background.graphics.beginFill(0xFF0000,0.75);
background.graphics.drawRoundRect(0,0,tfProgramName.textWidth+10,this.height+10,5,5);
background.graphics.endFill();

textWidth in my case is something like 373, but it should be closer to 400. It's definitely close, but it doesn't seem to take into account the font or font size.

like image 623
Alexandru Petrescu Avatar asked Nov 15 '22 03:11

Alexandru Petrescu


1 Answers

I can't promise it will be any better, but take a look at TextLineMetrics It gives you more information than anything else, so this is probably your best bet.

like image 194
Tyler Egeto Avatar answered Feb 01 '23 23:02

Tyler Egeto