Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

TextField align right not working

Participant ,
Jul 02, 2010 Jul 02, 2010

I have a really simple block of code to make a textfield, and I want it aligned right, but I haven't gotten it work:

            var tf:TextField = new TextField();
            tf.autoSize = "right";
            tf.height = 20;
            tf.width= 330;
            tf.text = "Man, alive!";
            tf.x = 5;
            tf.y = 5;
            addChild(tf);

I've tried using tf.autoSize = TextFormatAlign.RIGHT, but that doesn't seem to work, either.

Can anyone tell me what I'm doing wrong, please?

TOPICS
ActionScript
2.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 02, 2010 Jul 02, 2010

You need to use TextFormat class to assign the alignment.  "autosize" is not what you think it is, and based on your trying to set the size of the textfield, you probably don't want to use it.  Try adding the following before you assign the text and comment out the autosize line...

var tfFormat:TextFormat = new TextFormat();
tfFormat.align = TextFormatAlign.RIGHT;
tf.defaultTextFormat = tfFormat;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 02, 2010 Jul 02, 2010

Thanks, Ned, but nothing changed (!). Here's how my code looks now:

var tf:TextField = new TextField();
            //tf.autoSize = "right";
            tf.height = 20;
            tf.width= 330;
            tf.text = "Man, alive!";
            tf.x = 5;
            tf.y = 5;
            var tfFormat:TextFormat = new TextFormat(); 
            tfFormat.align = TextFormatAlign.RIGHT;
            tf.defaultTextFormat = tfFormat;
            addChild(tf);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 02, 2010 Jul 02, 2010

I am shaking my head...

The answer is just this:

tf.setTextFormat(tfFormat);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 02, 2010 Jul 02, 2010
LATEST

Actually, the answer was just what I said... "before you assign the text" but what you did will work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines