Categories
General

Font embedding WTF in Flash

I’m sorry if this is old news, but I was absolutely horrified to realise today that if you have to embed fonts in every single dynamic TextField on the stage, even if they are all using the same font!

I don’t know about you but I really hate when things don’t work as they should and there’s no obvious reason why this should be.

Anyway, I discovered that if you set the TextField.embedFonts property to true, then all the text fields just magically work. But it’s a pain to do this in code right? And it’s an even bigger pain to manually set the fonts to embed on every dynamic TextField on the stage.

I’ve just knocked together a simple recursive function that iterates through everything on the stage and when it finds a TextField it sets this property:

function embedFontsInTextFields(container : DisplayObjectContainer) : void
{
	for(var i: int = 0; i< container.numChildren; i++)
	{
		var child : DisplayObject = container.getChildAt(i);

		if(child is DisplayObjectContainer)
			embedFontsInTextFields(child as DisplayObjectContainer);
		else if (child is TextField)
			TextField(child).embedFonts = true;
	}
}

And call this function either on the timeline or in the document class :

embedFontsInTextFields(this);

PLEASE NOTE! This will only work if the font is actually embedded somewhere in one of your TextFields. It just saves you having to set the embed properties manually in your entire FLA.

This seems to work for everyone who’s tried it on a variety of browsers but please let me know how it works for you.

And Adobe, please sort this out. I hardly ever have to deal with localisation or dynamic text but when I do it’s always a complete arse.

A BIG THANK YOU to all the tweeters who helped me check that this worked: @eliias @monkeyarmada @grapefrukt @specialmoves @arthurlockman @matthbooth @thetandingo @palofigueiredo @robslegtenhorst @joeriBorst @vlh @philterdesign @anatomic @krzysztofc @savvas @nobuti @milkybrain @legojoe @kjtten @swingpants

21 replies on “Font embedding WTF in Flash”

Cool solution for what is definitely a major shortcoming in Flash’s text handling.

I have a feeling that with posts like this and the recent stuff on Jesse Freeman’s blog, Adobe is about to face their next “Make some noise”-like grass roots campaign for the Flash player.

Text/Fonts etc are so cruddy in Flash.

nice, interesting to only apply embed fonts. couldn’t you pass the textfield in your grip to a utility class for applying any of the attributes available to textfield.
😉

function embedFontsInTextFields(container : DisplayObjectContainer) : void
{
	for(var i: int = 0; i< container.numChildren; i++)
	{
		var child : DisplayObject = container.getChildAt(i);

		if(child is DisplayObjectContainer)
			embedFontsInTextFields(child as DisplayObjectContainer);
		else if (child is TextField)
			TextDecorator.localisableTextField(child);
	}
}

in AS2 you could hack the TextField prototype with maybe a dash of ASSetPropFlags magic. Maybe it would be “better” to extend TextField -> TextFieldWithEmbedFonts?

In any case, isn’t all this up in the air with TLF?

i don’t suppose theres a way of doing this in AS2? I still live in the dark ages

@Chad yes I’m sure… well they’ve been promising to sort out text in Flash for years now, even demoing new capabilities scheduled for FP10 and then quietly not actually releasing them…

@byteface absolutely! Once you’ve found the TextFields you can do anything you like with them. Is your TextDecorator class proprietary or something that’s available?

@Jon Williams I personally prefer to keep layout FLAs code free but yes you could do it that way if you’re laying stuff out with code.

@chris no idea, sorry. But I remember AS2 fonts just being HORRIBLE. Even more horrible than it is now! Perhaps others here may have some advice for you?

srry TextDecorator was just the pattern as was talking thoeretically. can also decorate to apply effects, filters, databinding or even just externalising properties like x,y,z to an external file.

In case of localisation and styling, I have a good several.. lots of contributers to each and for different projects can be quite good. I attempt bespoke solution per project using concepts from each, so I just get a large undocumented set of utilities. I need to do that so that its right for that job as some things require a lighter solution others require something more full featured.

best hack I found though, if your not a flex junkie and love flash but want to create quickly create font files that have the correct locale. You edit the unicode.xml files punctuation node to accept more unicode ranges. Then you can compile required locales glyph ranges from flash no probs. been using that one years 😉

ill ping you a mail now… see if the classes I got any use to you.

Does this apply when you manually embed fonts in the Flash IDE? I tend to embed fonts this way and with a recently completed, multi-language project I’ve had no end of font woes. Would it be best to embed everything in code?

@Julian brilliant! That’s such a good script, I particularly like how it snaps the fonts to pixels too. (See you at FOTB!)

@byteface cool! ALthough I haven’t received anything yet… try sebleedelisle at gmail dot com

@Ian Thomas It doesn’t really embed anything so you need to make sure the fonts are embedded in at least one text field. But as long as the font is embedded somewhere in your fla it ensures that all the other text fields also use the embedded version.

Thank you for this post. Yes, fonts in Flash have been chocked full of bugs in both AS2 and AS3. Gets even worst if you do any of the following:

1) You have one font file and attempt to share the fonts at run-time
2) Have .fla with special (but properly installed) fonts and it’s opened in bot the Mac and PC Flash IDE

I won’t go into all the issues, but this has been my #1 issue for AAA game development with Flash (AS2). This is my #2 hot issue for casual Flash development (AS3), only next to seamless MP3 looping being near impossible requiring a ass-backwards hack to look at raw bytes to get around gaps in looping…but I digress.

Cheers.

Hey Seb,
Here is a post I did regarding several other font issues, some of which are related to Flash and some more to operating system in combination with Flash;
//www.oddlystudios.com/?p=559
I’d particularly look at the last bit of the post as it has relevance to the embedFonts technique you mention.
Cheers!

Great point, I have been built sites/apps for localising in the pass few years, it has always been a pain to embed font for every textfield if not done dynamically, hope Adobe will solve this problem or maybe add one static property like Textfield.embedAll = true…

I don’t know whether you’ve notified the authoring or Player team of what you’d like… adobe.com/go/wish or bugs.adobe.com/flashplayer would make sure you’re in there, thanks.

jd/adobe

PS: I haven’t proofed the plaint myself.

Flex’s text components automatically check to see if their fonts are embedded or not. Wouldn’t that be nice if it were the default for all TextFields in Flash Player?

@John Dowdell: I hope the reverse is true; that Adobe keeps abreast of the blogs of Flash notables (like Seb’s).

I tracked down this thread to give some more details on an issue I have with font export in Adobe CS4. I’m sure the problem exists in Win & Mac but I demoed this on Windows XP.

If I create two (or more) named font objects in Flash, $foo and $bar but they both point to the same font face (e.g., “Broadway”) only one will exist in the export.

This happens for both AS2 (where I really need it for work) and as well as for AS3. I confirmed this via Sothink Decompiler 4 on my SWFs.

Comments are closed.