Flash: bold and regular embedded fonts using a stylesheet

Often you will have to combine bold and regular fonts in the same textfield, but with a textfield generated with actionscript. First, create two font symbols with the “bold” and “regular” styles.

Then, register the font styles:

Font.registerFont(BoldStyle);
Font.registerFont(RegularStyle);

Note: there is a difference between your font family (say, “Helvetica”) and the “BoldStyle” and “RegularStyle”.

BoldStyle is a class name. “Helvetica” is a font family name.

You need to “register” your class name, but you assign your font family name as the font family.

var style:StyleSheet = new StyleSheet();

var bold:Object = new Object();
bold.fontWeight = "bold";
bold.fontFamily = "Helvetica";

var body:Object = new Object();
body.fontStyle = "normal";
body.fontFamily = "Helvetica";

style.setStyle("b", bold);
style.setStyle("body", body);

var label:TextField = new TextField();
label.styleSheet = style;
label.htmlText = "Hello World...";
addChild(label);

Flash: combining bold and regular fonts in the same textfield

To combine bold and regular fonts in a dynamic textfield on the stage is pretty straightforward, if you aren’t looking for a true bold

First, create your textfield on the stage:

Then, select the “Render as HTML option” for the text box:

Give your textfield an instance name:

Then set the text:

my_textfield.htmlText = "My Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam eget rutrum quam. Donec ultrices lacinia odio venenatis accumsan.";