Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In a card game I use a TextField in the middle to display the playing table number, but also to detect if a playing card has been played - using myTextField.hitTestObject(myCard) - which means the TextField's position and dimensions may not change:

enter image description here

My current AS3 code is:

        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;

        addChild(myTextField);

However the TextField's content (the String "#2029" in the above screenshot) is not in the center of it.

I can not set _middle.autoSize = TextFieldAutoSize.CENTER because this changes the width of the border and breaks hitTestObject().

Is there another way to align the text in the middle please?

like image 995
Alexander Farber Avatar asked Dec 05 '25 22:12

Alexander Farber


1 Answers

Set the align property of TextFormat.

format.align = TextFormatAlign.CENTER;

like image 97
taskinoor Avatar answered Dec 07 '25 20:12

taskinoor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!