Here it is a embedding font class by Maohao.
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;
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);
}
}
}
Brgds,
CP
October 13th, 2007 at 7:52 am
Just for the record: font embedding in Flash CS3 IDE does not support unicode ranges. To read further please read an article at flash tekkie.
June 6th, 2008 at 3:48 pm
Hey I just wanted to comment on the structure of your code. The industry has developed best practice methods for writing code. It will help your readers if you structure your code properly. See example below.
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.Font;
import flash.utils.getDefinitionByName;
public class SimpleTextPaneTestDrive01 extends Sprite {
var embeddedFont:Font = null;
function SimpleTextPaneTestDrive01() {
var embeddedFontClass:Class = getDefinitionByName(“Font1″) as Class;
var embeddedFontsArray:Array = Font.enumerateFonts(false);
var fmt:TextFormat = new TextFormat();
var tf:TextField = new TextField();
Font.registerFont(embeddedFontClass);
embeddedFont = embeddedFontsArray[0];
fmt.color =0xffffff;
fmt.size = 16;
fmt.font = embeddedFont.fontName;
tf.text = “hello world!”;
tf.setTextFormat(fmt);
}
}
}
June 20th, 2008 at 11:46 am
Argh, crap. This is the 40.001 script I’ve found on embedding font in AS3, and the shit still do not work.
Please, be extremely specific of the context when you throw something like this into cyberspace. Try to eliminate ALL guessing.
July 5th, 2008 at 4:22 am
Sven << this worked perfect.
Andre << your code has a smiley face in it, how is that standard?
for anyone using flex 3 not flash cs3 do this to embed the font
[Embed(source='../../../assets/fonts/urfont.otf',
fontName='urfont',
mimeType='application/x-font'
)]
private var fontclass:Class;
var embeddedFontClass:Class = fontclass;
October 9th, 2008 at 3:17 am
Follow this link, this sollution is more easy in all ways…
http://www.zedia.net/2007/using-embedded-fonts-in-flash-cs3-using-actionscript-3/
October 25th, 2008 at 7:48 am
So What do i replace Font1 in the code with cause it throws this error
ReferenceError: Error #1065: Variable Font1 is not defined.
at global/flash.utils::getDefinitionByName()
at Test()
October 28th, 2008 at 6:05 am
Sven, I had the same problems trying to understand it. I’ve finally got the answer:
Open Library, on the right hand side click “New Font…” and select the font you want. Here’s the gotcha: the name is NOT the linkage.
To add the linkage you have to add your font to the library, and THEN right-click and select “Linkage…”. Call it “Font1″ and the code above will work.
I’ve spent hours trying to figure this out. Such a stupid UI misstep made by the CS3 team…
April 22nd, 2009 at 4:01 pm
Sven, you rock!