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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With