0
votes

i'm writing a jsfl to change all textfields to an imported font, and i know how to change font face of textfield from this question JSFL - How to change the font of a text field?

the problem is that, i can change the font into an installed font, but i can not change it into an imported font named $NormalFont,here are some screen shot which may make me understood. enter image description here

below is the property of $NormalFont enter image description here

so in my code, i call the function like this:

textElement.setTextAttr("face", "$NormalFont");

nothing changed. but i do can manually change the text font like below: enter image description here

and i notice that here the name of the font is $NormalFont*,with a star. so i call the function like this:

textElement.setTextAttr("face", "$NormalFont*");

nothing changed again.

anyone can help me? because i have over 100 fla files to change...

1

1 Answers

0
votes

face here is Font family, which is Microsoft YaHei, not $NormalFont.

$NormalFont is the name property of the fontItem that you embed in Library.

(About the asterisk, I think it's there just to remind that it's an embedded font and nothing more. That's why in Library you don't see it on the fontItem, because you already know that it's an embedded font.)

For instance, if the font you embed is the first item in Library's item array:

fl.trace(document.library.items[0].font);//Microsoft YaHei  (1)
fl.trace(document.library.items[0].name);//$NormalFont

So you can use Microsoft YaHei or 微软雅黑:

textElement.setTextAttr("face", "Microsoft YaHei");
textElement.setTextAttr("face", "微软雅黑");

If you must use a custom name like $NormalFont, first find the item with the name $NormalFont in Library, then get the font attribute of it, then set it as face for the textfields.

var myFontItem;
var itemArray = document.library.items;
for (var i = 0; i < itemArray.length; i++) {
    if (itemArray[i].name == '$NormalFont') {
        myFontItem = itemArray[i];
    }
}

textElement.setTextAttr("face", myFontItem.font);

(1) There's a problem with this, is that JSFL can't get/set font styles of a fontItem in Library (or I don't know how, even AS3 has problems when it comes to fonts). In case of simple bold/italic fonts like YaHei Bold, just set it like this:

textElement.setTextAttr("bold", true);

But if you want to use more styles like black condensed etc, your best bet is to directly edit the font file data to make a new custom font and install it, so that the font name in Flash IDE is unique, then use that name. I had to do that once.