开发者

Is it possible to embed fonts at runtime to use for existing dynamic textfield instances in SWFs?

I'm trying to embed fonts at runtime in actionscript and it somewhat works. I can embed fonts by either using the embed tag or by loading a font library asset with a linkage name and use it with a new TextField. However, a textfield that exists on a movie clip already does not have the embedded font and is missing characters.

A quick example in code (textInstance exists on the movieclip):

var embeddedFonts = Font.enumerateFonts(); //Shows embedded font

var textFormat:TextFormat = textInstance.getTextFormat();

textInstance.text = "Don't be lazy"; //missing characters 

var textField:TextField = new TextField();

textFi开发者_运维百科eld.embedFonts = true;
textField.defaultTextFormat = textFormat;
textField.selectable = false;
textField.autoSize = TextFieldAutoSize.LEFT;
textField.multiline = true;

textField.text = "Don't be lazy"; //shows all characters
addChild(textField);

Is it possible to do this? I want to embed the font at runtime and I'm loading multiple SWFs and I don't want to embed the font in each SWF.


I assume you have textInstance already added to your swf and it has a TextFormat with the font you are loading later.

After loading your font into your swf you should either set the text again with textInstance.text = textInstance.text (if textInstance has a defaultTextFormat) or set the textFormat with textInstance.setTextFormat(textFormat), because the textfield doesn't update automatically upon loading a font.


I had to create a new TextFormat with the font and set it as the defaultTextFormat in order to get it to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜