Copy link to clipboard
Copied
Hi.
I created an Item that extends MovieClip and that has a TextField on it where it where it will display the item's name. I want to embed the font but I'm having trouble because the text won't display.
I read the embedFonts description (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#embedFo...) and I have formatted the TextField via a TextFormat instance with my chosen font.
My code:
import flash.display.MovieClip;
import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
public class Item extends MovieClip {
private var _sName:String = "";
private var _txtName:TextField = new TextField();
private var _nColor:uint = 0xAACC00;
private var _tfText:TextFormat = new TextFormat();
public function Item(s:String) {
//also tried embedding here but got the same result
_txtName.text = s;
_txtName.autoSize = TextFieldAutoSize.RIGHT;
_tfText.font = "Helvetica";
_tfText.size = 30;
_tfText.color = _nColor;
_txtName.setTextFormat(_tfText);
_txtName.antiAliasType = AntiAliasType.ADVANCED;
_txtName.embedFonts = true;
addChild(_txtName);
}
If I remove the embed part the text shows correctly. I'm at a loss, what order of elements do I need to use to embed the font correctly?
Thank you.
1. you should have a font in your library.
2. it should have a class name (eg, HelveticaClass)
3. you should be using something like:
var helvetica:Font=new HelveticaClass();
_tfText.font=helvetica.fontName;
Copy link to clipboard
Copied
To use the embedFonts property you would have to use an actual embedded font. The way you have it coded it is using system fonts.
I did a quick Google Search and this seems to explain how to embed fonts in AS3 quite well:
http://divillysausages.com/blog/as3_font_embedding_masterclass
Copy link to clipboard
Copied
1. you should have a font in your library.
2. it should have a class name (eg, HelveticaClass)
3. you should be using something like:
var helvetica:Font=new HelveticaClass();
_tfText.font=helvetica.fontName;
Copy link to clipboard
Copied
Thank you both very much. I ended up using kglad's method, but I bookmarked Nabren's link because it looked quite compreehensive and helpful.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now