Embed a Font in Flash CS45/5/2010 12:00 AM By Jeff B
If you’re looking to beef up your freelance resume, you’ll want to show future employers that you’re up on all the latest web development trends. Being able to make use of fonts other than old standbys like Arial and Times might just help set you apart from other freelancers.
One of the best aspects of using Flash as opposed to pure HTML is that this sophisticated bit of web development technology allows you to choose any font you want for your projects. But in order for it to appear correctly and not fall back on whichever fonts the user has installed, you’ll want to embed your fonts in your movie files.
Thankfully, Flash offers this very ability. You’ll need a TrueType version of your font and the following ActionScript example:
// ActionScript 3.0 [Embed(source="assets/ARIAL.TTF", fontFamily="ArialEmbedded")] var ArialEmbedded:Class; var arialEmbeddedFont:Font = new ArialEmbedded(); var textFormat:TextFormat = new TextFormat(); textFormat.color = 0xFF0000; textFormat.font = arialEmbeddedFont.fontName; textFormat.size = 32; var textField:TextField = new TextField(); textField.autoSize = TextFieldAutoSize.LEFT; textField.wordWrap = true; textField.defaultTextFormat = textFormat; textField.embedFonts = true; textField.text = "The quick brown fox jumps over the lazy dog."; textField.width = 500; textField.x = 25; textField.y = 25; addChild(textField);
The first line uses the [Embed] metadata to specify the font file, which you’ll need to have uploaded to your server (the “source” bit is the filepath to the TrueType file). The “fontFamily” bit can be changed to echo the name of the font you’re using, and the “arialEmbeddedFont” var can also be changed—just make sure to be consistent in your naming, or your script won’t be able to find what it’s looking for.