Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Embed fonts on classic TextField doesn't work, even with TextFormat applied

Participant ,
Feb 25, 2013 Feb 25, 2013

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.

TOPICS
ActionScript
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 25, 2013 Feb 25, 2013

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;

Translate
Engaged ,
Feb 25, 2013 Feb 25, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2013 Feb 25, 2013

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 26, 2013 Feb 26, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2013 Feb 26, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines