Font embedding problems in Flash CS3 IDE
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):
[ftf w=”400″ h=”150″][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;[/ftf]
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.
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:
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:
[ftf w=”400″ h=”150″]
var format:TextFormat= new TextFormat();
format.font = new myEmbeddedFont().fontName; // format.font= “myFont”;
var myTextField= new TextField();
myTextField.embedFonts= true;
myTextField.defaultTextFormat = format;[/ftf]
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.
[flash http://www.nivas.hr/blog/wp-content/uploads/2007/06/dinamicinputembedtest_din.swf w=250 h=110]
Embedded standard 07_55 hr, which should work, but it doesn’t. :(
[flash http://www.nivas.hr/blog/wp-content/uploads/2007/06/dinamicinputembedtest_standard.swf w=250 h=110]
22 thoughts on “Font embedding problems in Flash CS3 IDE”
June 8, 2007 at 16:25
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! :-)
June 8, 2007 at 16:29
Thank you for such nice words! Glad I could help. :)
June 14, 2007 at 14:44
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. ;-)
June 14, 2007 at 15:28
Seven, your hack is great. Since some days I was working about it but no way, until now.
June 17, 2007 at 18:58
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?
June 20, 2007 at 08:27
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!
July 30, 2007 at 08:55
Good stuff! But hey, what do I do if I want to use a css stylesheet instead of the TextFormat class?
July 31, 2007 at 12:10
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. :)
September 17, 2007 at 03:52
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…
September 19, 2007 at 01:28
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.
September 19, 2007 at 11:38
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.
September 24, 2007 at 19:42
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…!
October 8, 2007 at 18:05
Yes, this is unfortunate.
I’ve now concluded my research on this issue as well. Please find it here
October 19, 2007 at 13:50
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;
;-)
October 20, 2007 at 10:57
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/
October 29, 2007 at 20:52
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.
November 22, 2007 at 11:05
Man, it’s 2:03 and Flash failing to render my font is not something I need. Thanks a bunch.
December 14, 2007 at 17:53
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.
January 16, 2008 at 12:34
Fantastic! For me too it ended a headache.
Incredible that Adobe didn’t document this clearly.
March 12, 2008 at 02:33
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.
August 3, 2008 at 21:49
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..
January 21, 2009 at 09:01
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