开发者

as3 dynamically runtime font embedding

开发者 https://www.devze.com 2023-02-10 08:50 出处:网络
I have a AS3 project in Flash CS4 in which I am dynamically loading in a font whose location is passed in via XML. It works when I write in the font name (here EASTERAR.T开发者_开发技巧TF). However, i

I have a AS3 project in Flash CS4 in which I am dynamically loading in a font whose location is passed in via XML. It works when I write in the font name (here EASTERAR.T开发者_开发技巧TF). However, if I replace it with a variable, I get an invalid metadata error. How can it be solved?

Works fine

[Embed(source='C:/fonts11/EASTERAR.TTF', fontFamily="xyz")]

var xyz:Class;

var arialEmbeddedFont:Font = new xyz();

var textFormat:TextFormat = new TextFormat();
textFormat.color = 0xFF0000;
textFormat.font = arialEmbeddedFont.fontName;
textFormat.size = 32;

var textField:TextField = new TextField();
textField.autoSize = TextFieldAutoSize.LEFT;
textField.wordWrap = true;
textField.defaultTextFormat = textFormat;
textField.embedFonts = true;
textField.text = "rohan";
textField.width = 500;
textField.x = 25;
textField.y = 25;
addChild(textField);

Shows meta-data error

var fontname:String = 'EASTERAR.TTF'
[Embed(source='C:/fonts11/'+fontname, fontFamily="xyz")]

Thanks.


You can't use variables in Embed metatags (in fact, you can't use in any meta).
And don't think that you can embed a font in runtime too...

What you can do is embed a font in a swf and load this file dynamically, at runtime.

To exemplify:
Create a new FLA file, embed your font and export to ActionScript, then, export the file.
Now, create another FLA, use URLLoader to download the previous SWF and use getDefinitionByName (flash.utils.getDefinitionByName) to get access to the font inside the loaded SWF. Now you can change the font of your text to the new font.

0

精彩评论

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