actionscript-3flashflashdevelopfont-embedding

How to embed a font in as3 using FlashDevelop?


How can you embed a font in as3 using FlashDevelop? I have read a lot of posts regarding this issue but none of them helped me solving it. When I use the following code, nothing is displayed (this is all the code) :

package  
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFormat;

    public class Main extends Sprite 
    {
        [Embed(source="/../resources/fonts/andbasr.ttf", fontName = "andbasr", fontWeight = "Demibold", mimeType="application/x-font")]
        private var andbasr:Class;

        public function Main() 
        {
            var textField:TextField = new TextField();
            textField.embedFonts = true;
            var format:TextFormat = new TextFormat("andbasr", 16, 0x000000);
            textField.defaultTextFormat = format;
            textField.text = "Test";
            stage.addChild(textField);
        }

    }

}

"andbasr" is just a random ttf file I found. Any idea of what I am doing wrong?


Solution

  • It works ok, I just downloaded font that you are testing. I think font doesn't have DemiBold weight, also in your case, as you don't use TLF TextField, disable embedding of font in DF4 format by embedAsCFF="false"

    [Embed(source="AndBasR.ttf",
            fontName = "myFont",
            mimeType = "application/x-font",
            advancedAntiAliasing="true",
            embedAsCFF="false")]
    private var myEmbeddedFont:Class;
    
    //Testing 
    var textField: TextField = new TextField();
    textField.defaultTextFormat = new TextFormat("myFont", 20);
    textField.embedFonts = true;
    textField.text = "Test Embedded Font";
    
    addChild(textField);