4

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?

Nicolas Siver
  • 2,875
  • 3
  • 16
  • 25
user3240131
  • 187
  • 1
  • 2
  • 11

1 Answers1

10

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);
Nicolas Siver
  • 2,875
  • 3
  • 16
  • 25
  • Awesome! embedAsCFF="false" was the solution. I do not understand why though. I am going to gather some information about TLF TextFields and DF4 format... Thanks a lot! – user3240131 Mar 12 '14 at 13:37
  • Adding a note since this solution initially did not work for me, but after some research, it did. This requires Flex SDK 3 or higher, which I did not have. If anyone comes across this and has problems, check the Flex SDK configuration – FlashV8 Mar 09 '22 at 02:44