Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple textformat won't work

Status
Not open for further replies.

sirugo

Programmer
Aug 1, 2000
162
SE
The following setting of textformat does not change any of the text's properties:

this.createEmptyMovieClip("mcX", 0);
mcX.createTextField("tfX", 0, 200, 0, 200, 20);
var tf:TextFormat = new TextFormat();
tf.font = "Verdana";
tf.size = 30;
tf.color = 0xff0000;
tf.align = "right";

tfX.setTextFormat(tf);
mcX.tfX.text = "Hi";


Why?
 
I believe you have to set it as a 'new' text format, so just edit your code to be:

Code:
tfX.set[b]New[/b]TextFormat(tf);
 
[tt]//
this.createEmptyMovieClip("mcX", 0);
mcX.createTextField("tfX", 0, 200, 0, 200, 20);
var tf:TextFormat = new TextFormat();
tf.font = "Verdana";
tf.size = 30;
tf.color = 0xff0000;
tf.align = "right";
mcX.tfX.setNewTextFormat(tf);
mcX.tfX.autoSize = true;

mcX.tfX.text = "Hi";
//[/tt]

thatrenowned was right but you also have to specify the target correctly. I added "autoSize"; otherwise your 30px text won't fit in 20px TextField!

Kenneth Kawamoto
 
But...the tf-align makes no difference!
I tried "center", "left", "right" with different values of the width (i.e 300) at
mcX.createTextField("tfX", 0, 200, 0, 300, 20);
 
OK, solved it.
Changed autosize to "center" instead of true, then removed the align property:

this.createEmptyMovieClip("mcX", 0);
mcX.createTextField("tfX", 0, 0, 0, 300, 10);
var tf:TextFormat = new TextFormat();
tf.font = "Verdana";
tf.size = 18;
tf.color = 0x0a7a23;
tf.bold = true;
mcX.tfX.setNewTextFormat(tf);
mcX.tfX.autoSize = "center";
mcX.tfX.text = "Hi";
 
Oh, I wouldn't want word-wrapping here...
=)

Thanks anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top