actionscript-3flashtextfieldtextformat

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

https://i.sstatic.net/z2f0B.png

I have embedded the bold font:

https://i.sstatic.net/LSson.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.


Solution

  • 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.