package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.Font;
import flash.utils.getDefinitionByName;
public class SimpleTextPaneTestDrive01 extends Sprite
{
private static var embeddedFont:Font = null;
//CONSTRUCTOR
public function SimpleTextPaneTestDrive01()
{
var embeddedFontClass:Class = getDefinitionByName(“Font1″) as Class;
Font.registerFont(embeddedFontClass);
var embeddedFontsArray:Array = Font.enumerateFonts(false);
embeddedFont = embeddedFontsArray[0];
var fmt:TextFormat = new TextFormat();
//fmt.bold = true;
fmt.color =0xffffff;
fmt.size = 16;//Old day fashion: If you embed it in a textfield on stage
//fmt.font = “Helvetica”;
fmt.font = embeddedFont.fontName;
var tf:TextField = new TextField();
tf.text = “hello world!”;tf.setTextFormat(fmt);
}
}
}
Links:
Loading fonts at runtime
Using hasGlyphs() with embedded fonts
July 30, 2007 at 10:35 am |
[...] July 30th, 2007 · No Comments Here it is a embedding font class by Maohao. [...]
August 1, 2007 at 10:23 am |
[...] Embedding fonts in Flash CS3/AS3 [...]
October 8, 2007 at 12:40 pm |
Unfortunately it still doesn’t work with unicode text
March 20, 2008 at 2:08 am |
Excuse me, but I think you forgot to use
tf.embedFont = true;
April 28, 2008 at 4:00 pm |
It didnt work
April 28, 2008 at 4:02 pm |
Man, embedding fonts via AS3 is too dificult … I´ve been trying for months with thousands of examples … I´m using Vista … help please
July 24, 2008 at 1:25 pm |
http://www.adobe.com/devnet/flash/quickstart/embedding_fonts/
Take a read of this buddy.
August 19, 2008 at 5:47 am |
Yay! Thanks.
September 17, 2008 at 4:10 pm |
Dorian: even so, Flash CS3 IDE fails embedding unicode fonts. Only Basic Latin chars make it through the compilation. Added the odd behaviour of renaming the font instances, it’s surely a bug.
February 5, 2009 at 4:12 am |
Follow the following steps first and then try .. it works:
To embed a font symbol:
1. Select Window > Library to open the current FLA file’s library.
Open the library that you want to add the font symbol to.
2. Select New Font from the library’s pop-up menu (upper-right corner of the Library panel).
3. Type a name for the font symbol in the Name text box of the Font Symbol Properties dialog box.
4. Select a font from the Font menu or type the name as “Font1″ of a font in the Font text box.
5. Select Bold, Italic, or Alias text if you want to apply a style to the font.
6. Enter the font size to embed, and then click OK to apply the changes and return to your document.
Your font now appears in the current document’s library.
from:http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000893.html
June 23, 2009 at 9:17 am |
Many thanks! I’ve been searching for info on how to embed a font in an external swf then load it at runtime for ages. With a slight variation of this method – embedding the font in an external file, loading then registering the font I’ve finally succeeded.
cheers!