Pregunta

Code:

var BoldTextFormat:TextFormat = new TextFormat();
BoldTextFormat.bold = true;
weapons[player.activeWeapon].weaponName.defaultTextFormat = BoldTextFormat;

This seems very simple, but it is not doing anything! The text is not becoming bold at all.

Using weapons[player.activeWeapon].weaponName.setTextFormat(BoldTextFormat); does nothing also.

These traces:

trace(weapons[player.activeWeapon].weaponName);
trace(weapons[player.activeWeapon].weaponName.defaultTextFormat);
trace(BoldTextFormat);

Result in this output:

[object TextField]
[object TextFormat]
[object TextFormat]

And this is the text field I am trying to make bold:

http://i.stack.imgur.com/z2f0B.png

I have embedded the bold font:

http://i.imgur.com/l9qJ95X.png

What could possibly be wrong? There are no errors. Tracing the text field's text shows the correct text, so that can't be the problem.

¿Fue útil?

Solución

You might need to embed the bold font, your image shows 'Regular' font.

Ok, I figured out the magic here. Likely why it started working for you is that you actually set the bold font for your field.

But here's the magic. In the library, right-click on the bold font and choose properties. Then go to the actionscript settings and enable :

export for actionscript

Next, in your code you need to add this line :

BoldTextFormat.font = "Times New Roman Bold";

That should work.

Sadly, the .bold of the TextFormat doesn't seem to automatically find the bold version.

Otros consejos

Try :

 weapons[player.activeWeapon].weaponName.setTextFormat(BoldTextFormat);

defaultTextFormat applies to text that is added after you set the format, if you want to change the format of text that is already set you should use setTextFormat

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top