Font embedding problems in Flash CS3 IDE

Author: seven June 6, 2007

While I was making a comprehensive test of Croatian letter input field issues in Flash Player 9 (check it out here), I accidentally discovered potential bug, or very strange feature in new Adobe Flash CS3. Embedding fonts in Flex is easy as 1-2-3, doing the same in CS3 IDE is somehow awkward (broken?).

In Flex you would do this (pseudo exemplary code):

[Embed(source="C:\WINDOWS\Fonts\myfont.ttf", fontFamily="myFont")]
...
var format:TextFormat= new TextFormat();
format.font= "myFont";
var myTextField= new TextField();
myTextField.embedFonts= true;
myTextField.defaultTextFormat = format;

Yeah, that works fine. Ok, how to do this in CS3 IDE? First, you import your font to library - select a font, name it somehow.
font import
Secondly you export it for ActionScript. In theory (as I interpreted Flash help files), you should just use exact font name you entered as format.font property for a TextFormat. In practice - Flash IDE never renamed your font. In fact, if you selected Bitmap Text during the font import, Flash IDE will rename your font suffixing it with '_8pt_st' (in case you selected 8px size). So actually instead using your own name inside TextFormat.font property, you should use the original font name.

Here is a screenshot of a debugger so we all can contemplate about this:
font embed problem
Debugger shows contents of embeddedFonts array:
var embeddedFonts:Array = Font.enumerateFonts(false);

So how to embed fonts trough an IDE? There is a hack. :) Assuming that you have a font in your library which you exported with the class name myEmbeddedFont - instead of using font name in format.font property, you point to the exported library class name (format.font = new myEmbeddedFont().fontName;) like this:

var format:TextFormat= new TextFormat();
format.font = new myEmbeddedFont().fontName; // format.font= "myFont";
var myTextField= new TextField();
myTextField.embedFonts= true;
myTextField.defaultTextFormat = format;

The part that troubles me the most, is not the strange renaming inside the IDE, well it does because it's not documented anywhere, but thing that bothers me is the fact that I was unable to display Croatian letters in my old pixel fonts. What am I missing here? Anybody?

Embedded DINMittelschrift HR CZ, Croatian letters show up nicely.
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Embedded standard 07_55 hr, which should work, but it doesn't. :(
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Author
seven
CEO/CTO at Nivas®
Neven Jacmenović has been passionately involved with computers since late 80s, the age of Atari and Commodore Amiga. As one of internet industry pioneers in Croatia, since 90s, he has been involved in making of many award winning, innovative and successful online project. He is experienced full stack web developer, analyst and system engineer. In his spare time, Neven is transforming retro-futuristic passion into various golang, Adobe Flash and JavaScript/WebGL projects.

    22 thoughts on “Font embedding problems in Flash CS3 IDE”

  • Thank you so much!! Made my day, have been googling all day for how to do font-embedding in cs3, read a 100 adobe docs, where I found your solution as a comment to one of them.. Fantastic! :-)

  • Thank you for such nice words! Glad I could help. :)

  • Just out of curiosity.. Have you tried to make this work with labels? I had to give up in the end, and convert my labels to TextFields, which worked fine anyway. Annoying though. ;-)

  • Seven, your hack is great. Since some days I was working about it but no way, until now.

  • Thank you, your tip was a great help. When you embed a font in Flex, I take it it embeds the entire font, not just the latin chars? Is that true? As far as I know, Flash IDE only embeds latins + numbers/ some symbols, unless embed manually using authoring environment(hassle). Were you able to get Croatians in older vers. of Flash?

  • Wow, I have always found text to be a bit of an issue in flash – and even more so in CS3. Your post has helped immensely. Thanks!

  • Good stuff! But hey, what do I do if I want to use a css stylesheet instead of the TextFormat class?

  • I have check it out css stylesheets. Didn’t have time to play with it. Actually, I tried to avoid css in cs3 until now. :)

  • There is no multibyte support as unicode chars like фывафвыа or šžšžšž. I can’t quite get how did you manage to get Croatian chars to appear.

    This is total madness. The whole thing is utterly broken and not usable. We can imagine how many frameworks it has broken for the Flash developers…

  • There is few workaround, eg. you can create dummy textfield on the stage with letters you need, and then create another from the code and use those letters.

    I haven’t tried embedding/using our chars in Flex, but it can’t get much worse than Flash 9 IDE.

  • For the existing framework done in AS2 it seems quite an overhead to produce a textfield to replace a library font esp under the circumstances in which the quality of the embedded chars is not reasonable. In fact, I failed to compile a field with embedded chars in a way that all the chars would display properly.

    As for the CS2 products Adobe’s QA has remained terrible and despite the fact that the font embedding has always been troublesome, Flash CS3 compiler is undoubtedly the worst compiler I’ve seen for Flash and I’ve seen them since Flash 4.

  • Ain, I wouldn’t go so far and say the as3 compiler is terrible. The sad fact remains, fonts are handled so wrong. :(

    If somebody knows how to embed font to TextArea in cs3, give me a buzz…!

  • Yes, this is unfortunate.

    I’ve now concluded my research on this issue as well. Please find it here

  • You can use your dynamic classes (http://www.nivas.hr/blog/2007/10/04/dynamic-class-names-are-neat/) for fonts as well:

    var embeddedFontClass:Class = getDefinitionByName(embededFontName) as Class;
    Font.registerFont(embeddedFontClass);
    var font = new embeddedFontClass().fontName;

    var fmt:TextFormat = new TextFormat();
    fmt.font = font;

    ;-)

  • Cool trick Og2t, thanks!

    Btw, I really love flightboard effect on your site! We had to do something similar for one online campaign – http://www.nivas.hr/pub/s&s-tmobil-flex-728/

  • Hi Og2t thank you for your trick!

    I started a project to gather every Flash/Flex issues and questions related to fonts embedding. SAEF project (Share About Embedding Flash/Flex).
    http://analogdesign.ch/blog/index.php/archive/flash-flex-font-embedding-information-sharing-project-saef-project/
    Don’t hesitate to make suggestions and/or modifications.

  • Man, it’s 2:03 and Flash failing to render my font is not something I need. Thanks a bunch.

  • call me thick, but i must still be missing something,, do you actually create a class called myEmbeddedFont()? and if so, what do you put in this class? I’ve tried your way, and it throws an error like:

    1180: Call to a possibly undefined method myEmbeddedFont.

  • Fantastic! For me too it ended a headache.

    Incredible that Adobe didn’t document this clearly.

  • Thanks a lot! As others I spend hours and hours reading thousands faq’s and howto’s -and this one finally saved my a…source code.

  • Hi,
    I still cant make my code work…

    var font:Font = new f1(); //from library
    var format:TextFormat = new TextFormat();
    format.font = new f1().fontName;
    format.color = 0x000000;
    format.size = 12;
    format.letterSpacing = 0.8;

    //var tf:TextField = new TextField();
    k1.embedFonts = true;
    k1.antiAliasType = AntiAliasType.ADVANCED;
    k1.autoSize = TextFieldAutoSize.LEFT;
    k1.selectable = false;
    k1.defaultTextFormat = format;
    k1.text = “Collections”;

    this is my code… k1 is a name of a dynamic text field that i have created in screen.. i hav created a mask for th layer that contains this text field..so its not visible, thats the reason i want to embed the font. but its not at all working.. pls tell me what am missing..

  • Hi,

    Might be useful to some one… just make sure you have not applied the font that is required for embedding, in the FLA.

    For instance, if you need to embed a font (say Hobo), use any method that suites you best – preferably CSS, but ensure that Hobo is not applied to any of your text boxes either on stage or on the library. Use some font that you are sure will never be used in the project for *all* text boxes (say Garamond). Then, apply Hobo through script to the text boxes.

    If in case you are not able to see an embedded font, it can mean only one thing – that there is at least one instance of a text box some where within the FLA, which has that particular font applied to it. Please note that it doesn’t matter if the text box is Static, Dynamic or Input.

    ~ Shiyaz

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>