Flash CS3/CS4 Embedding Fonts.. the right way – UPDATED

Yep it’s been awhile since I’ve posted anything, I’ve actually been busy with project work (and a lot of it), but I figured I would take a second or two and post something so that my blog didn’t dry up.

I’ve been having a helluva time embedding fonts. SOME times they work some times they don’t. So I found this nifty way to do it.

1. Create a new font in the library and name it the actual font’s name. For instance if you wanted to create ‘Myriad Pro’ font, do so naming it ‘Myriad Pro’
2. Export the font for linkage, removing any spaces in the name. Typically flash will do this for you.
3. In your actionscript declare the TextFormat.font value as: new MyriadPro().fontname

var _fmt:TextFormat = new TextFormat();
_fmt.font = new MyriadPro().fontName;

This is the real key. By declaring it a new font, it imports the font and makes it accessible in your class/function. I’ve noticed that just using the font’s name doesn’t always work for whatever odd ball adobe reason (aka: bug).

AS3 Class Method

There’s also another way to do it w/o using a library item

Create a class and the very first line of the constructor use the [Embed] meta tag followed by a private var like so:

package com {	
	public class GlowText {
		[Embed(source="C:\\WINDOWS\\Fonts\\Arial.ttf", fontFamily="Arial")]
		private var fnt:String;
	}// end Class
 
}// end Package

When you initially test your class, you may get a warning telling you that flash needs to update the flex sdk path. Click ‘OK’ and re-test



2 comments


    its_b

    December 31, 2009

    Hi,

    i have tried the first method of importing the fonts and its working
    can u help me in reducing the size of the swf after importing the font as shown in the first method i.e., acquiring only required symbols from the font.

    Cam

    December 31, 2009

    @its_b:
    From what I understand this isn’t possible to do this via actionscript. You would have to do this in a TextField and change the embedding settings to the characters you want to import. Alternatively, you could create a version of your font using only the characters you want to import (http://ilovetypography.com/2007/10/22/so-you-want-to-create-a-font-part-1/). Hope this helps.

You must be logged in to post a comment.