PDA

View Full Version : Align Text!



daniel619
July 20th, 2007, 02:34 PM
I have a ticket object and I want text to be center aligned in the middle of it. Why won't it work!?


ticket = new TicketGraphic();
addChild(ticket);

ticket.filters = [new DropShadowFilter(5, 135, 0x000000)];

ticketTxt = new TextField();
var textFormat = new TextFormat();
textFormat.align = TextFormatAlign.CENTER;
ticketTxt.text = ticketName;
ticketTxt.y = -9;
ticketTxt.x = -(ticket.width/2);
ticketTxt.width = ticket.width;
ticketTxt.textColor = 0xFFFFFF;

ticket.defaultTextFormat = textFormat;
ticket.addChild(ticketTxt);

cesig
July 20th, 2007, 02:45 PM
Well, for one, you don't actually apply the TextFormat to the same TextField that you instantiate in the code you provided. That might be a problem.

But once you add the TextFormat to the TextField, there are still issues. Adding the line below helps, though. But I don't think it should be required to center-align the text. So I'm not entirely sure what the issue is.


ticketTxt.autoSize = TextFieldAutoSize.CENTER;