Reputation: 281
I'm trying to embed a font to my Actionscript 3 project in Flash Builder 4.5. I've found several examples and fixes, but none of them has my problem. My embedded font shows up in the enumeratedFonts list and I get no errors, but it just falls back to the system default font when I use it in my TextFormat. I've tried using several Embed()-attributes and compiler-arguments from this post: http://divillysausages.com/blog/as3_font_embedding_masterclass
package {
import flash.display.Sprite;
import fl.text.TLFTextField;
import flash.text.TextFieldAutoSize;
import flash.text.Font;
import flash.text.TextFormat;
import flashx.textLayout.elements.*;
import flashx.textLayout.formats.*;
public class FontTest extends Sprite {
[Embed(source="assets/Nanami.otf", fontName="NanamiRegular", embedAsCFF= "false")]
private var myEmbeddedFont:Class;
public function FontTest() {
var fonts:Array = Font.enumerateFonts(false);
for(var i:int = 0; i < fonts.length; i++) {
trace(fonts[i].fontName);
}
var fmt:TextFormat = new TextFormat();
fmt.color = 0xFF0000;
fmt.font = "NanamiRegular";
fmt.size = 32;
var tlfTxt:TLFTextField = new TLFTextField();
tlfTxt.defaultTextFormat = fmt;
tlfTxt.embedFonts = true;
tlfTxt.border = true;
tlfTxt.text = "Lorem ipsum dolor sit amet.";
tlfTxt.wordWrap = true;
tlfTxt.width = 300;
tlfTxt.autoSize = TextFieldAutoSize.LEFT;
tlfTxt.x = tlfTxt.y = 40;
tlfTxt.rotation = 20;
addChild(tlfTxt);
}
}
}
Upvotes: 1
Views: 11810
Reputation: 810
Can you try to change the fontName
to something else, like "testfontname" and provide a font-family, like "testfontfamily"
[Embed(source="assets/Nanami.otf", fontName="testfontname", fontFamily="testfontfamily" embedAsCFF= "false")]
then embed it with that name:
fmt.font = "testfontname";
Upvotes: 2
Reputation: 860
If you're using TLFTextField, you must change "embedAsCFF" value to true, because TLFText using new Flash Text Engine.
Upvotes: 0