Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
I am shaking my head...
The answer is just this:
tf.setTextFormat(tfFormat);
Copy link to clipboard
Copied
Actually, the answer was just what I said... "before you assign the text" but what you did will work.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more