A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Basic Font Embedding

  1. #1
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429

    Basic Font Embedding

    I'm trying to understand why my embeded fonts wont work in AS3. I have extensive experience with this in AS2 but something has changed that's just not working.

    I'm using the CS3 authoring tool to compile an .fla.
    I included a font symbol in the library, set the linkage name to Fruitiger, checked export for AS and first frame and included the base class flash.text.Font.

    Then in the class that needs it I imported flash.text.Font, flash.text.TextFormat, and flash.text.TextField.

    The class is similar to this:

    PHP Code:
    package{
      
    import flash.text.TextField;
      
    import flash.text.TextFormat;
      
    import flash.text.Font;
      public class 
    Demo extends Sprite{
        var 
    txtFormat:TextFormat;
        public function 
    Demo(){
          
    txtFormat = new TextFormat();
          
    txtFormat.font "Fruitiger"

          
    var tf:TextField = new TextField();
          
    tf.background true;
          
    tf.backgroundColor 0xFF0000;
          
    tf.embedFonts true;
          
    tf.text "Test Text";
          
    tf.setTextFormat(txtFormat);
          
    addChild(tf);
        }
      }

    I get a red square on the stage but no text and no errors.
    Any ideas on what I'm doing wrong?

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Hmm, seems to be a bit of a bug in CS3.
    I appears that no matter what name you use as the export class name in the linkage, the string assigned to the TextFormat.font property must be the entire name listed in your loaded fonts list.
    For example, when you create a new font symbol in the library, if the font chosen in the Font dropdown list is Fruitiger LT Std 55 Roman, then your text format object must look like this:

    myTextFormat = new TextFormat();
    myTextFormat.font = "Fruitiger LT Std 55 Roman";

    I realize this is probably not a widely encountered issue as the preferred method of embedding fonts is likely using the [Embed] directive in a font class.

  3. #3
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    No bug. You need to give your font a clas name. Every object is a class. Then you write:

    var fnt:Font= new Fruitiger();
    var txtFormat:TextFormat = new TextFormat();
    txtFormat.font = fnt.fontName;
    var tf:TextField = new TextField();
    tf.text = "Test Text";
    tf.embedFonts = true;

    tf.setTextFormat (txtFormat);
    addChild (tf);
    - The right of the People to create Flash movies shall not be infringed. -

  4. #4
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    Thanks for that Cancer. For some reason the verbose name also works without the object creation or calls to registerFont()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center