flash cs4 loading font from external swf

Here is a pretty basic overview of how to load fonts from a .swf, great for sites that have many languages, particularly asian characters, where you may need to specify characters or fonts while not wanting to load them all into a single swf.

Note: this is for flash CS4 as it utilizes the mxmlc embed tag which gives you more control over font loading.

add embed tag in empty fla

[code lang="actionscript"]
[Embed (systemFont="Arial" fontName="myFont")]
var myFont:Class

you can even specify what utf-8 characters to embed if you want non-roman characters

load the published font .swf into your .swf

[code lang="actionscript"]
var myLoader:Loader = new Loader();
myLoader.load(...path to your font.swf)

…upon load…

[code lang="actionscript"]
var font:Font = MovieClip(myLoader.content).myFont as Font;

…you must register the font in order to use it…

[code lang="actionscript"]

…then format you text as you normally would with an embedded font.

[code lang="actionscript"]
textFormat.font = font
textField.embedFonts = true;
textField.text = "text goes here"

hope that helps.

Leave a Reply

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