Align the content of the TextField, but keep its width x height

In a card game, I use a TextField in the middle to display the game table number, and also to determine if the playing card was playing - with myTextField.hitTestObject(myCard)

- this means that the position and dimensions of the TextField may not change: / p>

enter image description here

My current AS3 code:

        var format:TextFormat = new TextFormat();
        format.color = 0xFFFFFF;
        format.size = 30;
        format.bold = true;

        myTextField.defaultTextFormat = format;
        myTextField.border = true;
        myTextField.borderColor = 0xFFFFFF;
        myTextField.x = W/2-Card.W/2;
        myTextField.y = Card.H;
        myTextField.width = Card.W;
        myTextField.height = Card.H/4;



However, the content of the TextField (String "#2029"

in the above screenshot) is not in the center of it.

I can't install _middle.autoSize = TextFieldAutoSize.CENTER

because this changes the border width and splits hitTestObject()


Is there any other way to align the text in the middle?


source to share

1 answer

Set the property align



format.align = TextFormatAlign.CENTER;



All Articles