Why can't I display embedded fonts in AS3?

I looked at all the topics about inserting fonts in AS3 that I could find, and tried all the solutions. I probably missed something obvious, but I donโ€™t quite understand what Iโ€™m doing, so please direct me in the right direction. Many of the answers are related to Flash Builder or another tool, but I use FlashDevelop . I donโ€™t know if that matters.

I have this line in my Main.as:

[Embed(source = "assets/SKA_75_marul_CE_extended.ttf", fontName = "SKA_75_marul_CE_extended", fontWeight = "bold", advancedAntiAliasing = "true", mimeType = "application/x-font")] public static var SKA_75_marul_CE_extended:String; 

And this exists in an extended sprite constructor called Pointer.as:

 var format:TextFormat = new TextFormat(); format.font = "SKA_75_marul_CE_extended"; format.color = 0xFFCCCC; format.size = 20; var label:TextField = new TextField(); label.defaultTextFormat = format; label.text = "test"; label.embedFonts = true; label.antiAliasType = AntiAliasType.ADVANCED; //label.setTextFormat(format); --> I tried this too, didn't work... label.defaultTextFormat = format; label.x += img.width + 50; this.addChild(label); 

The only way I found to display it is to disable embedFonts. I tried to implement C: /windows/fonts/arial.ttf without success.

Embedding fonts seems like a dark art like no other, and I have to give in after 1 hour of struggle. Please send help.

UPDATE:

Here the working code, it turns out, was due to the correct order of operations ...:

 [Embed(source="assets/SKA_75_marul_CE_extended.ttf", fontName = "myFont", mimeType = "application/x-font", fontWeight="normal", fontStyle="normal", unicodeRange="U+0020-U+007E", advancedAntiAliasing="true", embedAsCFF="false")] private var myEmbeddedFont:Class; var tf:TextFormat = new TextFormat( "myFont", 20,0xffffff ); var t:TextField = new TextField; t.embedFonts = true; // very important to set t.defaultTextFormat = tf; t.text = text; tx += img.width + 50; t.width = 700; this.addChild( t ); 
+8
flash fonts actionscript-3 flashdevelop
source share
1 answer

This is the most DEFINITIVELY "dark art" to get embedded fonts to work properly. I would first check if "SKA_75_marul_CE_extended" is the actual name that has the font in its metadata (I used Suitcase Fusion to extract the name). I also saw TTF fonts that Flash simply refuses to embed (possibly invalid metadata could crash the embed system). I would continue testing with a well-known working font until I find the actual problem if this is a problem with the font file.

One thing I noticed is "public static var SKA_75_marul_CE_extended: String;" ... shouldn't it be of type Class?

FlashDevelop font insert a link from someone who had problems: http://www.flashdevelop.org/community/viewtopic.php?p=28301

+5
source share

All Articles