A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Problem embedding fonts in dynamically-created (code-only) TextField

  1. #1
    Junior Member
    Join Date
    Sep 2008
    Posts
    12

    Problem embedding fonts in dynamically-created (code-only) TextField

    I've done some other AS3 code-only text fields before, but I think I'm missing something here. With the code shown below, my text shows up, and seems to have the right font embedded in it, but when I uncomment the line that sets the embedFonts property of the TextField to true, all the text disappears. Here's the code section (constructor function) where it happens:

    Code:
    		public function Pflio() {
    			txt1.color = 0xFFFFFF;
    			txt2.color = 0xFFFFFF;
    			txt3.color = 0xFF0000;
    			txt1.size = txt2.size = txt3.size = _typeSize;
    			txt1.font = 'Myriad Pro Bold';
    
    			for (var i = 0; i < 9; i++) {
    				grid[i] = new TextField();
    				//grid[i].embedFonts = true;
    				grid[i].defaultTextFormat = txt1;
    				grid[i].text = chars[i];
    				grid[i].width = 50;
    				grid[i].height = 50;
    				grid[i].selectable = false;
    				addChild(grid[i]);
    			}
    		}
    I've embedded the font with the Class name 'MyriadProBold,' and there's more code to import packages, declare class properties, set up the TextFormat object, etc., but hopefully what's shown above will let you spot what's wrong, if anything.

  2. #2
    Senior Member
    Join Date
    Apr 2008
    Location
    Nottingham, UK
    Posts
    348
    should you apply the texformat before embedding the font? also, does the font name contain spaces or is it camel case?
    Dan

  3. #3
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    How does your TextFormat look like? The text should not disappear.
    - The right of the People to create Flash movies shall not be infringed. -

  4. #4
    Junior Member
    Join Date
    Sep 2008
    Posts
    12
    Quote Originally Posted by dan_hin
    should you apply the texformat before embedding the font? ...Dan
    Before? Do you have any references for that? I've usually been doing it after setting the property, and have noticed other devs doing that also; e.g.:

    http://www.marcosweskamp.com/blog/archives/000113.html

    Quote Originally Posted by dan_hin
    ...does the font name contain spaces or is it camel case?
    Dan
    Only the class name for the font is camelCase, as I remember it. The Name has spaces in it. Does that help?

  5. #5
    Junior Member
    Join Date
    Sep 2008
    Posts
    12
    Quote Originally Posted by cancerinform
    ...The text should not disappear.
    I feel the same way!

    Quote Originally Posted by cancerinform
    How does your TextFormat look like?..
    txt1 and _typeSize are properties of the class, and here's how I've set up txt1:

    Code:
    		private var _typeSize:Number = 50;
    		public var txt1:TextFormat = new TextFormat();
    
    		public function Pflio() {
    			txt1.color = 0xFFFFFF;
    			txt1.size = txt2.size = txt3.size = _typeSize;
    			txt1.font = 'Myriad Pro Bold';
    This's on a movie file with a 0x000000 background.

    Does that help?

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You need to declare a new font. Also you need to export the class in frame 1. Try that:
    var fnt:Font=new MyriadProBold();//class name here
    txt1.font = fnt.fontName;
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Junior Member
    Join Date
    Sep 2008
    Posts
    12
    Quote Originally Posted by cancerinform
    You need to declare a new font. Also you need to export the class in frame 1. Try that:
    var fnt:Font=new MyriadProBold();//class name here
    txt1.font = fnt.fontName;
    Hmmm... I tried that, and my type shows up, but it's in Helvetica, not MPB (I'm on a Mac.).

    Why would you use all that extra code? I needed to import another package too, which violates the best practice of 'Package Parsimony.'

    Do you have a link or reference you can share? Or can you explain why to do that?

  8. #8
    Junior Member
    Join Date
    Sep 2008
    Posts
    12
    Quote Originally Posted by cancerinform
    You need to declare a new font. Also you need to export the class in frame 1. Try that:
    var fnt:Font=new MyriadProBold();//class name here
    txt1.font = fnt.fontName;
    Why would you use all that extra code? I needed to import another package too, which violates the best practice of 'Package Parsimony.'

    Do you have a link or reference you can share? Or can you explain why you'd bother to do that?

    Also, I tried it, and my type shows up, but it's in Helvetica (I'm on a Mac) instead of MPB.

  9. #9
    Junior Member
    Join Date
    Sep 2008
    Posts
    12
    Sorry for the double post - one of my post previews must've gone up when I wasn't looking.

    Anyway, I think I've fixed the problem by more carefully matching the Font's Symbol Name (which was correct) to the Symbol's Font Name (which matched the Class Name, but was missing the spaces).

    I've yet to see any good resources that cover all 3 of those names for font embedding, and if you have one, please feel free to give me a link.

    Thanks!

  10. #10
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    - The right of the People to create Flash movies shall not be infringed. -

  11. #11
    Junior Member
    Join Date
    Sep 2008
    Posts
    12
    Thanks, cancerinform!

    If anyone else has something good about this, please add a link.

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