Runtime font swapping

Based on Ivan Dembicki’s work at http://www.sharedfonts.com/eng/index.html

For fonts, you need two SWFs
FONTID-lib.swf
- a textfield which embeds all glyphs needed, with bold/italic as necessary, inside a movieclip which is exported for runtime sharing. movieclip has script which registers the textformat of the field with a shared “font manager” object
FONTID.swf
- a practically empty movie which contains the imported movieclip from FONTID-lib.swf

A shared font manager which registers textformats against an identifier. You can then use the same font manager to use these textformats for any textfield. Copy font, bold and italic properties to a  new TextFormat object, so colour and size are ignored.

A loading routine to load the FONTID.swfs. The point of the excercise is that you can load these programmatically so you can use one font for English text and a different font for Russian text, while keeping the same base movie.

You seem to need both FONTID-lib.swf and FONTID.swf – you can’t just load the FONTID-lib.swf

I think the export URL in FONTID-lib.swf is not important (it doesn’t seem not be written into the SWF?).

The export URL in FONTID.swf is important and is relative to the base URL of the overall parent movie. Therefore these FONTID.swf files are not portable between different site structures. You can use e.g. swfmill and ANT to create different versions of the FONTID.swf quickly per deployment environment.

This is something I’m using for an AS2 project – better solutions may exist for AS3 (or indeed for AS2….)

Leave a Reply