Hi all,
For our current project we need to have ALL fonts externalized and loaded dynamically so our client is able to replace them when localizing text.
Our designers have already designed everything in several FLA files, using the original fonts for English text. If we are going to load these fonts dynamically, it is no good to have them embedded in every FLA file, right? So what I did is to set all text fields as dynamic and also to "use device fonts", so the font does not get embedded in the swf.
But once I load the font in AS3 and attempt to apply it to each text field, I get a blank textfield (all characters gone)! Just to be clear, I'm doing something like this:
But the strange thing is: If I create a new TextField() and assign the exact same set of properties (new TextFormat() with the same font name "MyFont" and everything else)... the text shows up fine!
Is this expected behavior? Am I doing anything wrong?
Thanks in advance!
This is my simplified project setup:
screens.fla (contains user interface, artwork, textfields, etc) -> screens.swf
MyFont1.ttf -> embedded in MyFont1.as -> MyFont1.swf
MyFont2.ttf -> embedded in MyFont2.as -> MyFont2.swf
Bunch of .as files -> main.swf which loads all other swfs.
What I'm trying to do is to have screens.swf compiled without MyFont embedded into it. But I don't want to have all text fields with "_sans" font because I have several textfields using 3 or 4 different fonts and I want to maintain that information.
As for step 2, I thought that setting the textfields to "use device fonts" would do just that: not embed the font but maintain the reference of the font name.
in MyFont1.fla, click the upper right of the library panel > click new font > select your font family and style > tick the needed character range(s) > click the actionscript tab > tick export for actionscript > type a class name (eg, VerdanaReg) > tick tlf or classic > click ok > file > publish.
in screens.fla, add:
var verdanaReg:Font;
var loader:Loader=new Loader();
loader.addEventListener(Event.COMPLETE,completeF);
loader.loader(new URLRequest("MyFont1.swf"));
function completeF(e:Event):void{
var loadedAppDomain:ApplicationDomain = e.target.content.loaderInfo.applicationDomain;
var C:Class = loadedAppDomain.getDefinition("VerdanaReg") as Class;
verdanaReg= Font(new C());
embedFontF(tf,verdanaReg);
}
function embedFont(tf:TextFeidl,font:Font):void{
var tfor:TextFormat=new NextFormat();
tfor.text = font.fontName;
tf.embedFonts=true;
tf.defaultTextFormat = tfor;
// if there's already text in tf, also use:
tf.setTextFormat(tfor);
}
North America
Europe, Middle East and Africa
Asia Pacific