|
-
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.
-
should you apply the texformat before embedding the font? also, does the font name contain spaces or is it camel case?
Dan
-
Senior Member
How does your TextFormat look like? The text should not disappear.
- The right of the People to create Flash movies shall not be infringed. -
-
 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
 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?
-
 Originally Posted by cancerinform
...The text should not disappear.
I feel the same way! 
 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?
-
Senior Member
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. -
-
 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?
-
 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.
-
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!
-
Senior Member
- The right of the People to create Flash movies shall not be infringed. -
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|