Search code examples
actionscript-3embedded-fonts

AS3: Embed font two different fonts with same name


I'm embedding a font in AS3 with the following command:

[Embed(source="../font/font1.swf", fontName = "FontName1", fontWeight = "bold" )]
private var myEmbeddedFont:Class;

var _tf: TextFormat;

_tf = new TextFormat();
_tf.color = 0x000000;
_tf.size = 18;
_tf.font = "FontName1";

Now I would like to embedd a second font which is the same font but not bold. My problem now is: Both vonts (the bold one and the non-bold) have the same name.

What can I do to use both fonts? In the embedding-command fontName="" must be the "real" name of the font. Is there some Kind of an alias I can set for the font-name?


Solution

  • you want to use fontFamily and not fontName. Also, why is your font an .swf? here's what I use :

        [Embed(source="../font/font1.ttf", embedAsCFF="false", fontFamily="FontName1")]
        private static const Font:Class;
        [Embed(source="../font/font1_Bd.ttf", embedAsCFF="false", fontFamily="FontName1", fontWeight="bold")]
        private static const FontBold:Class;
    

    With that, AS3 should be able to display both normal anf bold text with your font.