# Aligning A Textfield As3

**URL:** <https://forum.kirupa.com/t/aligning-a-textfield-as3/310003>\
**Category:** flash\
**Created:** [May 29, 2010, 8:20pm UTC](https://forum.kirupa.com/t/aligning-a-textfield-as3/310003 "2010-05-29T20:20:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![FreeHugs](https://avatars.discourse-cdn.com/v4/letter/f/59ef9b/32.png) [@FreeHugs](https://forum.kirupa.com/u/FreeHugs)\
**Post date:** [May 29, 2010, 8:20pm UTC](https://forum.kirupa.com/t/aligning-a-textfield-as3/310003/1 "2010-05-29T20:20:16Z")

</div>

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?

```php
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 😕
