Aligning A Textfield As3

Hey everybodys,

This problem has been bugging me for ages, how can I align a textfield to a point on the stage so that the text is centered exactly on that point? Everything I try seems to be a slightly off, and i’ll need some solution that works for all font sizes which is proving extremely differcult :fight:

This is what I’v come up with but I need to change that divisor of ‘10’ to something different when I change the font size and surely there is an easier way to do this?

import flash.geom.Point;
import flash.text.TextField;
import flash.text.TextFormat;

var alignTo:Point = new Point(stage.stageWidth / 2, stage.stageHeight / 2);

var myText:TextField = new TextField();
var myFormat:TextFormat = new TextFormat();

myFormat.size = 80;
myText.defaultTextFormat = myFormat
myText.text = "Testing"

myText.width = myText.textWidth + int(myFormat.size) / 2;
myText.height = myText.textHeight + int(myFormat.size) /2;
myText.x = alignTo.x - myText.textWidth / 2 - int(myFormat.size) / 10;
myText.y = alignTo.y - myText.textHeight / 2 - int(myFormat.size) / 10;

addChild(myText);

I’m sure someone out there has hit this problem before :confused: