Search code examples
actionscript-3stylesheet

Can't embed multiple fonts and use them in same textfield - cs5, as3


having a bit of trouble getting embedded fonts to work. The inconsistency with this is driving me crazy. I've gotten this to work before but not since going to cs5.

My set up is as follows:

I have a dynamic textfield on stage named "tf".

The following code populates the textfield and attempts to style one word, "love" in the sentence with a different font.

_style = new StyleSheet();

var styleObj  = new Object();
styleObj.color = '#FF0000';
styleObj.fontFamily = 'Futura Bold Oblique';

_style.setStyle('.otherText', styleObj);
tf.styleSheet = _style;
tf.htmlText = 'I <span class="otherText">love</span> it when stuff works!';

The font is embedded and set to export for actionscript with the export name Font1. The word "love", which is supposed to be displayed as the font Futura Bold Oblique just disappears. It makes no difference if I use the font screen name listed in the properties panel for that font or if I use the export instance name I gave it.

My sentence looks like : I it when stuff works! As you can see, "love" is gone. Come on people, show me some love! lol.

Anyone have an idea why this isn't working. This is highly essential to my daily work and its driving my crazy!! Thx!

I have been playing around with this since posting, hoping that maybe that specific font was causing the trouble, but its not the font. I tried using different styles of Helvetica Neue as separately embedded fonts and got the same result.


Solution

  • Fixed it, sort of. using enumerateFonts. This lists the fonts' names as Flash sees them. Copy and paste from the output window, and use that for the stylesheet fontFamily property. It still seems that Flash thinks some different styles from the same family, like Futura Bold and Futura Bold Oblique are the same; in my case it listed them both as Futura Book. In order to get the Oblique text in there I had to embed two separate versions of the font, Futura and Futura BT.

    private function getFontNames():void
    {
        var fontArray:Array = Font.enumerateFonts(false);
        fontArray.sortOn("fontName", Array.CASEINSENSITIVE);
    
        for(var i:int = 0; i<fontArray.length; i++)
        {
            trace(fontArray[i].fontName);
        }
    }