简体   繁体   中英

Basic TextFormat change is doing nothing

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 trace s:

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM