Skip to main content
Inspiring
December 16, 2010
Question

Embedding and using external fonts.

  • December 16, 2010
  • 1 reply
  • 1636 views

I'm using Flash CS4.  I'm trying to load and embed an external font.  The main problem I'm having is that I need to import more than just latin 1.  I need many special characters imported as well.  Because of this, using Flash CS4's create new font from the library is not an option.  I'm using Verdana, so I know the font has all the characters I need.

So what I need to do is create an external swf that holds the font.  Then I need to import and use the font.  Unfortunately, I've found way too many ways online that work but don't fit my needs.

Any help is appreciated.

This topic has been closed for replies.

1 reply

Inspiring
December 17, 2010

What are you the needs that solutions you found do not fulfill?

Do you mean "load" at runtime when you say "import"?

Inspiring
December 17, 2010

Correct.  I need to load the font at runtime.  I also need the ability to specify which Unicodes to use.  I guess my frustration with the matter is, I can't find complete solutions anywhere online.  I keep finding bits and pieces of different ways of doing this.

This is what I need to do:

1. On runtime, load the external swf file that contains an embedded font.

2. Once the swf is loaded, apply the embedded font to a dynamic text box.

This is what I need to find out:

1. How do I embed a font into a swf that allows me to specify which unicodes to use.

2. I know how to import the swf on runtime.

3. Once the swf is imported, what do you do to start using the font?  How and what do you reference from the imported swf to use the font?

Any HELP to clarify this is VERY appreciated.

Inspiring
December 17, 2010

1. Embedding

a. You can embed font in Flash IDE by creating Font as a library asset and then compile this swf. There are tons of help available on Internet.

b. If you use Flash CS5 or compilers that utilizes Flex SDK, you can create class like below and compile it into a swf:

package 
{
     import flash.display.Sprite;
     public class FontLibrary extends Sprite
     {
          [Embed(systemFont="Verdana", fontName="_verdana", mimeType="application/x-font", advancedAntiAliasing="true", fontStyle="normal",unicodeRange="U+0020-U+007E")]
          public static var Normal:Class;
          [Embed(systemFont="Verdana", fontName="_verdana", mimeType="application/x-font", advancedAntiAliasing="true", fontStyle="normal", fontWeight="bold",unicodeRange="U+0020-U+007E")]
          public static var Bold:Class;
          [Embed(systemFont="Verdana", fontName="_verdana", mimeType="application/x-font", advancedAntiAliasing="true", fontStyle="italic", fontWeight="normal",unicodeRange="U+0020-U+007E")]
          public static var Italic:Class;
          [Embed(systemFont="Verdana", fontName="_verdana", mimeType="application/x-font", advancedAntiAliasing="true", fontStyle="italic", fontWeight="bold",unicodeRange="U+0020-U+007E")]
          public static var ItalicBold:Class;
     }
     
}

No matter what way you choose - you will have font available the external swf.

Try to load external swf into current domain. When you load the swf there is no much to do. Once swf is loaded - fonts should be available throughout application.

To use the font - just pass its name into TextFiled instance's TextFormat. WIth the example above:

myTextFormat.font = "_verdana";

Documentation for TextFormat:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextFormat.html

To see available fonts you can use the following:

var allFonts:Array = Font.enumerateFonts(false);
allFonts.sortOn("fontName", Array.CASEINSENSITIVE);     
for (var i:int = 0; i < allFonts.length; i++)
{
     trace(allFonts.fontName);
}