是否可以在运行时嵌入字体以用于 SWF 中现有的动态文本字段实例?
我正在尝试在运行时将字体嵌入到动作脚本中,它有点有效。我可以通过使用嵌入标签或加载具有链接名称的字体库资源并将其与新的 TextField 一起使用来嵌入字体。但是,影片剪辑上存在的文本字段没有嵌入字体并且缺少字符。
代码中的一个简单示例(影片剪辑上存在 textInstance):
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();
textField.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);
可以这样做吗?我想在运行时嵌入字体,并且正在加载多个 SWF,但我不想在每个 SWF 中嵌入字体。
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();
textField.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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您已经将
textInstance
添加到您的 swf 中,并且它有一个TextFormat
以及您稍后加载的字体。将字体加载到 swf 后,您应该使用
textInstance.text = textInstance.text
再次设置文本(如果textInstance
有一个defaultTextFormat
)或者使用textInstance.setTextFormat(textFormat)
设置 textFormat,因为加载字体时文本字段不会自动更新。I assume you have
textInstance
already added to your swf and it has aTextFormat
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
(iftextInstance
has adefaultTextFormat
) or set the textFormat withtextInstance.setTextFormat(textFormat)
, because the textfield doesn't update automatically upon loading a font.我必须使用该字体创建一个新的 TextFormat 并将其设置为 defaultTextFormat 才能使其正常工作。
I had to create a new TextFormat with the font and set it as the defaultTextFormat in order to get it to work.