R – actionscript 3 and using fonts

actionscript-3apache-flexfonts

How can I make my strings and text attributes bold in my actionscript code?

I'm working with the code behind pattern so i have an mxml component with a text attribute. I then have my actionscript component where I concatenate three text attribute and set them as the text property on the mxml text component.

I want to be able be flexible with the styles of each text field I concatenate. I want the first text bold and the last bold however. Any ideas?

Best Answer

If you want to use different font weights for a text, you have no other choice than creating 2 text components (Label, Text, ...).

If you use external fonts, be sure to embed both normal and bold fonts :

@font-face
{
    src:                    url("calibri.ttf");
    fontFamily:             calibri;
    advanceAntiAliasing:                    true;
    fontWeight:             normal;
}

@font-face
{
    src:            url("calibrib.ttf");
    fontFamily:     calibri;
    fontWeight:     bold;
}

and set some styles in your css like :

.calibri16
{
    font-size: 16;
    font-weight:normal;
    font-family:calibri;
    color: #666666;
}

.calibri16b
{
    font-size: 16;
    font-weight:bold;
    font-family:calibri;
    color: #666666;
}

You can then set the styleName property of your text components :

<HBox>
<Label id="myLabel" styleName="calibri16b" text="This is bold" />
<Label id="myLabel2" styleName="calibri16" text="and regular" />
</HBox>

In Action Script :

myLabel.styleName = "calibri16b";
myLabel2.styleName = "calibri16";