Patrick
Patrick

Reputation: 63

AS3 TextField Fonts

I have problems setting a font in AS3. I have tried several different things using ressources from forums and questions but I can't get it to work.

Here's the code I use:

    private function addContentToMovieClips(Text:String, MC:MovieClip):void
    {
        var myFont = new Trebuchet();

        var tFormat:TextFormat = new TextFormat();
        tFormat.font = myFont.fontName; 
        tFormat.color = 0x000000;
        trace(tFormat.font);

        var tf:TextField = new TextField();
        tf.defaultTextFormat = tFormat;
        tf.embedFonts = true;
        //tf.antiAliasType = AntiAliasType.ADVANCED;
        tf.text = Text;
        MC.addChild(tf);
        tf.width = 300;
    }

In the library, I have a Font named "font2" with AS linkage "Trebuchet". I get no compiler errors and text seems to be created on the screen but nothing is displayed.

The following line is for debugging:

trace(tFormat.font);

And returns "Trebuchet MS" as expected.

I'd be very grateful if you can help me understand why this does not work!

Cheers,

Patrick

Edit: when removing

tf.embedFonts = true;

the text is displayed with the correct font. Not sure why but this does the trick for now.

Upvotes: 0

Views: 2567

Answers (1)

Kodiak
Kodiak

Reputation: 5978

You should have pasted the code where you embed the font. But since I've had the same problem, I guess you missed the embedAsCFF directive:

[Embed(source="../someFont.ttf", 
    fontName = "myFont", 
    mimeType = "application/x-font", 
    fontWeight="normal", 
    fontStyle="normal", 
    unicodeRange="englishRange", 
    advancedAntiAliasing="true", 
    embedAsCFF="false")]

Upvotes: 0

Related Questions