Skip navigation
GeneralIroh
Currently Being Moderated

Problem with dynamically loaded fonts

Apr 15, 2012 10:33 AM

Tags: #fonts #textfield #embedfonts #dynamic_fonts #textformat

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:

 

  1. In a FLA file (CS5) I create a text field with some text using some font, say, "MyFont".
  2. I set the textfield to dynamic and use device fonts.
  3. I export the FLA file to textfield.swf, and "MyFont" is not embedded. So far so good.
  4. I create a swf containing just "MyFont".
  5. I load MyFont.swf and call Font.registerFont(...)
  6. I load textfield.swf and set textField.embedFonts = true;
  7. Poof! All characters are gone.

 

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!

 
Replies
  • kglad
    61,990 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 15, 2012 1:18 PM   in reply to GeneralIroh

    what are you trying to do?

     

    if you're trying to load an embedded font family/style, step 2 doesn't make sense.

     
    |
    Mark as:
  • kglad
    61,990 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 15, 2012 5:47 PM   in reply to GeneralIroh

    ok, so you don't want screens.swf to be compiled with MyFont.   that's all you've clearly explained, so far.

     

    let me guess.  you want to load a swf that has MyFont embedded in it so you apply the embedded font to a textfield in screens.  is that correct?

     
    |
    Mark as:
  • kglad
    61,990 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 15, 2012 9:56 PM   in reply to GeneralIroh

    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);

    }

     
    |
    Mark as:
  • kglad
    61,990 posts
    Jul 21, 2002
    Currently Being Moderated
    Apr 16, 2012 7:36 AM   in reply to GeneralIroh

    what you're doing isn't going to work.  you've already figured that out.

     

    if you want to load fonts dynamically, follow my instructions.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points