Seb Lee-Delisle


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 :


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

This entry was posted in Actionscript, Flash, Obsolete. Bookmark the permalink.

21 Responses to Font embedding WTF in Flash