defaultTextFormat.align doesn't work - Solved

7 posts

Flag Post
m = new Matrix(1, 0, 0, 1, to.x, to.y);
var letter:String = (model as Letter).text.substr(0, 1);
text = new TextField();
text.width = text.height = 20 * scale;
text.defaultTextFormat = Main.textFormat(20 * scale);
text.embedFonts = true;
text.text = letter;
text.defaultTextFormat.align = TextFormatAlign.CENTER;
destination.draw(text, m);

doesn’t align or anything. nuff said. Tried both CENTER and RIGHT but nothing happens.

 
Flag Post

Use TextFormat class.

It states here http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html that defaultTextFormat “Specifies the format applied to newly inserted text, such as text entered by a user or text inserted with the replaceSelectedText() method.”

Here is a sample of TextFormat:-

var tf:TextField = new TextField(); 
tf.text = "Set this center"; 
 
var f1:TextFormat = new TextFormat(); 
f1.align = "center"; 
  
tf.setTextFormat(f1); 

you can also specify things like font, size, bold, italics etc with this too.

 
Flag Post

.defaultTextFormat = whatever should be before .text = whatevever

 
Flag Post

simplegoogly, I’m not quite sure about what you mean I’m doing wrong sorry. I’m using the TextFormat class, Main.textFormat returns new TextFormat("04b03", size, colour);
UnknownGuardian, I tried

text.defaultTextFormat = Main.textFormat(20 * scale);
text.defaultTextFormat.align = TextFormatAlign.CENTER;
text.embedFonts = true;
text.text = letter;

But it still doesn’t work.

 
Flag Post

Make your text field wider and then you’ll see it align (maybe)

 
Flag Post

You cannot put properties directly on the defaultTextFormat, just like you cannot directly push a filter to .filters. I believe it’s because defaultTextFormat uses a setter. What you need to do is make a text format, set the properties, THEN set defaultTextFormat = thatTextFormat.

var tf:TextFormat = new TextFormat();
tf.prop1 = foo;
tf.prop2 = bar;
tf.prop3 = shoosh;
tf.prop4 = doof;
tf.prop5 = pap;
tf.prop6 = nak;
myTextField.defaultTextFormat = tf;
 
Flag Post
Originally posted by truefire:

You cannot put properties directly on the defaultTextFormat, just like you cannot directly push a filter to .filters. I believe it’s because defaultTextFormat uses a setter. What you need to do is make a text format, set the properties, THEN set defaultTextFormat = thatTextFormat.

var tf:TextFormat = new TextFormat();
tf.prop1 = foo;
tf.prop2 = bar;
tf.prop3 = shoosh;
tf.prop4 = doof;
tf.prop5 = pap;
tf.prop6 = nak;
myTextField.defaultTextFormat = tf;

Thanks that worked!