Skip navigation
Currently Being Moderated

bold font in Flash not showing in SWF

Sep 7, 2010 9:00 AM

Hiya,

Sorry if this is a dumb question - I'm not an expert with Flash.

I'm adapting an off the shelf mp3 player and would like to make some text bold - namely [see: http://www.stevedrake.net/music_09] the text that shows the current artist/song at the top.

This is dynamic text from an XML file. I've embedded the fonts [Verdana regular and bold - OpenType] in Flash CS5 but the bold won't display even though the special characters do display [Jónsi].

Ta

steve

 
Replies
  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 7, 2010 10:31 PM   in reply to steve_London

    how are you indicating flash should display bold font?


     
    |
    Mark as:
  • Currently Being Moderated
    Oct 5, 2010 2:34 AM   in reply to steve_London

    Embeding some weights of the same font doesn't work properly in CS5. Use htmlText instead.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 29, 2010 1:57 PM   in reply to steve_London

    Has someone found a workaround for this bug/behavior ? I'm trying to publish a CS4 project in Flash CS5 and every bold font is broken. I can't use the htmlPropery and the <b> tag because it's not clean.

     

    thanks!

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 18, 2011 2:00 PM   in reply to sideDoor

    Yes, I think I also encountered this bug, and it's really a bad one.  Do the folks at Adobe realize that fonts are a MAJOR aspect of this form of media?  I have tried every trick in the book to get the Bold style of Univers 45 LT Light to show up on an exported .swf.  It seems it's just not possible.

     

    Can htmlText support fonts that are not necessarily for the web such as Univers?

     

    Any suggestions and / or pointers are greatly appreciated!  Thank you for your time and help!

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 11, 2011 12:08 PM   in reply to barbozza

    The correct answer is to use htmlText = "<b>" + theString + "</b>";

     

    This would have taken me forever to figure out why my bold fonts weren't showing up. Thanks for this.

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 29, 2011 5:29 PM   in reply to steve_London

    I got around this CS5 bug without using htmlText or ActionScript, as follows:

     

    In the font view, give your font a name, e.g. "VerdanaBold". Now go back to your TextField. Select it and view Properties. Under Character/Family, you should be able to enter "VerdanaBold*" (the name you gave your font, with the asterisk).

     

    Now the TextField should use the correct embedded font, with its proper weight.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 29, 2012 12:53 AM   in reply to steve_London

    Try turn off "Auto kern" in textfield properties panel

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 7, 2012 8:10 AM   in reply to Lexxx_87

    Was anybody able to solve it or find a workaround? Seems like I have a very similar (if not exactly the same) problem with CS6 as well. In my FLA I am embedding all the fonts and variations I want, which means:

     

    Arial

    Arial Bold

    Arial Italic

    Arial Bold Italic

     

    They all have their Linkage set to unique names, etc. I am not using them in manually created textfields but in textfields created with code (so no auto-kern). I am setting the variations with TextFormat - well, I would, if it was working. What I see is always only "Arial". The font variations appear as simple Arial as well, no bold, no italic, nada... If I change the font, for example, to Times New Roman, it is the same story. I see all the text in Times New Roman despite the fact that it should be Times New Roman Bold. This happens on my Macbook Pro.

     

    If I try to open the very same file on the other Mac or I use Windows to publish it -> voila! it works just fine without any modifications. So what's going on here?

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 19, 2012 7:39 PM   in reply to Fygo

    What's going on is that Adobe doesn't see this as a huge problem and fixing the issue is a low priority.  Look at how many people have read this thread:  over 3000!

     

    Do something Adobe!

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 29, 2012 3:33 PM   in reply to Lazlo Hollyfeld

    I am having the same issue dealing with the Arial Bold embedded font.  I want the classic dynamic textfield to only display bold text.  So here is what I have figure out.

     

    1) Set the textfield with the Arial Bold font embedded for the textfield.

     

    2) Creat code similar to the following:

     

    var myTextFormat:TextFormat = new TextFormat();

    myTextFormat.bold = true;

     

    3) Now set your text to your textfield first

     

    4) After you have updated your textfield with new text.  Now set the format to the textfield something like this:

    myTXT.setTextFormat(myTextFormat);

     

    Everytime you change the text in the textfield, just apply the format immediately afterwards and the textfield will be bold.

     

    If you only want part of the textfield bold, then you will need to use the htmlText with the html tags.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 2, 2012 2:01 AM   in reply to kglad

    I found what make this bug.

     

    The text format of flash.text.TextField is changing when setting text.

     

    The work around I found is AS3 only. Wasn't been able to find another solution yet.

     

    Here is what you can do:

     

    public static function setText(target:TextField, text:String):void{

                                  var textFormat:TextFormat = target.getTextFormat();

                                  target.text = text;

                                  target.setTextFormat(textFormat);

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 2, 2012 10:29 AM   in reply to IlyaG

    TextField.defaultTextFormat is defined for any fields you don't wish to continuously set the TextFormat object for. If you intend on setting the format once, use defaultTextFormat.

     

    http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fla sh/text/TextField.html#defaultTextFormat

     
    |
    Mark as:
  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    Dec 3, 2012 7:22 AM   in reply to sinious

    i actually think this is a bug.  i can't embed arial regular and arial bold in the same fla unless i use style sheets or static text.

     

    it doesn't matter whether i use a textfield created in the ide or with code.  it doesn't matter whether i try to use both weights in one textfield or in two different textfields.

     

    there's no problem embedding two different font families in one or more textfields.  but using the same font family with different weights/styles is a problem.

     

    here's sample code that displays part of the problem:

     

    import flash.text.TextFormat;

    import flash.events.FocusEvent;

    import flash.text.TextField;

     

    var n:int=0;

    var tf:TF = new TF();

    tf.width=400;

    tf.border=true;

    tf.embedFonts=true;

    addChild(tf);

     

    var tf_startText:String="this is a test: ";

    var tf_endText:String="textformat change.";

    tf.text=tf_startText+tf_endText;

     

    var tfor1:TextFormat = new TextFormat();

    var tfor2:TextFormat = new TextFormat();

    var tfor3:TextFormat = new TextFormat();

     

    // three fonts need to be embedded.  the first two should be from the same font family to show a problem. the third, from a different font family, confirms the code used for embedding and changing textformats is correct.

    var arialBold:Font = new Bold();

    var arialReg:Font = new Reg();

    var comicSans:Font = new CS();

     

    tfor1.font=arialReg.fontName;

    tfor2.font=arialBold.fontName;

    tfor3.font=comicSans.fontName;

     

    tf.setTextFormat(tfor1,0,tf_startText.length);

     

    tf.addEventListener(FocusEvent.FOCUS_IN,f);

    function f(e:FocusEvent):void {

        if (n%2==0) {

            tf.setTextFormat(tfor2,tf_startText.length,tf.text.length);

        } else {

            tf.setTextFormat(tfor3,tf_startText.length,tf.text.length);

        }

        n++;

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 3, 2012 8:05 AM   in reply to kglad

    Just use a TLFTextField. I embedded fonts in my library: Garamond Bold (exported for actionscript as GBold, type: TLF) and Garamond Regular (exported for actionscript as GRegular, type: TLF). Just numbers/letters embedded.

     

    I added a stage handler for click and on click it just formats a portion of the text with bold or no bold, works fine for me.

     

    Open new AS3 doc in Flash Pro. Embed any fonts like mentioned above and adjust the class name as needed below:

     

    import flash.events.MouseEvent;

    import fl.text.TLFTextField;

    import flash.text.Font;

    import flash.text.TextFormat;

     

    var useBold:Boolean = false;

     

    // fonts

    var gRegFont:Font = new GRegular();

    var gBoldFont:Font = new GBold();

     

    // handler

    stage.addEventListener(MouseEvent.CLICK, handleClick);

     

    function handleClick(e:MouseEvent):void

    {

        useBold = !useBold;

        tf.bold = useBold;

        tf.font = useBold ? gBoldFont.fontName : gRegFont.fontName;

     

        myTLFTextField.setTextFormat(tf, 17, myTLFTextField.length);

    }

     

    // TLFTextField init

    var myTLFTextField:TLFTextField = new TLFTextField();

    addChild(myTLFTextField);

    myTLFTextField.x = 10;

    myTLFTextField.y = 10;

    myTLFTextField.width = 400;

    myTLFTextField.height = 100;

    myTLFTextField.text = "This is my text: This is affected by format";

     

    var tf:TextFormat = new TextFormat(gRegFont.fontName,16,0x0,false);

    myTLFTextField.setTextFormat(tf,0,myTLFTextField.length);

     

    If I don't initially speecify a range on my setTextFormat() I was getting an oddity but it was fixed by always specifying a start/end index which is why my initial set does that.

     

    Click the stage and a portion of the text goes back and forth between Bold and Regular, no CSS needed.

     

    For the record I also did it with a regular flash.text.TextField. just change the class from TLFTextField to TextField and import flash.text.TextField. Works just fine as well.

     
    |
    Mark as:
  • kglad
    72,235 posts
    Jul 21, 2002
    Currently Being Moderated
    Dec 3, 2012 10:55 AM   in reply to sinious

    that's another work-around, in addition to using stylesheets. 

     

    it looks most like the stylesheet solution where applying a fontWeight property allows the use of a bold font but you're not really referencing the bold font name using actionscript.  the key part of your code is tf.bold which should not be needed if the fonts were embedded correctly (by flash).  this should be enough:

     

       tf.font = useBold ? gBoldFont.fontName : gRegFont.fontName;

     

    actually, you don't even need to explicitly reference the embedded bold font in the library.  just referencing the regular font is enough if you use the bold property of your textformat and i suspect the same is true using stylesheets.

     

    here's your edited code that doesn't need to reference the two embedded font names:

     

    import flash.events.MouseEvent;

     

    import flash.text.TextField;

    import flash.text.Font;

    import flash.text.TextFormat;

     

    var useBold:Boolean=false;

     

    // fonts

    var gRegFont:Font = new GRegular();

    //var gBoldFont:Font = new GBold();

     

    // handler

    stage.addEventListener(MouseEvent.CLICK, handleClick);

     

    function handleClick(e:MouseEvent):void {

        useBold=! useBold;

        tf.bold=useBold;

        //tf.font=useBold?gBoldFont.fontName:gRegFont.fontName;

        tf.font = gRegFont.fontName;

        myTLFTextField.setTextFormat(tf, 17, myTLFTextField.length);

    }

     

    // TLFTextField init

    var myTLFTextField:TextField = new TextField();

    myTLFTextField.rotation = 3;

    myTLFTextField.embedFonts = true

    addChild(myTLFTextField);

    myTLFTextField.x=10;

     

    myTLFTextField.y=10;

    myTLFTextField.width=400;

    myTLFTextField.height=100;

    myTLFTextField.text="This is my text: This is affected by format";

     

    var tf:TextFormat=new TextFormat(gRegFont.fontName,16,0x0,false);

    myTLFTextField.setTextFormat(tf,0,myTLFTextField.length);

     

    and there's still a problem using the code i suggested and there's a problem if you create two textfields in the ide and embed a regular font in one and bold font in the other using the properties panel to embed the fonts.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 3, 2012 1:43 PM   in reply to kglad

    I know what you mean, the outlines embedded should be thicker because we "think" it's embedding the fonts as 2 separate classes. I don't think it's this simple internally. You can see in the font manager it groups fonts variants (regular/bold/italic all under the same font name). Internally it's actually keeping track.

     

    This is actually behavior I don't mind. My example was more complex than it needed to be. I like when fonts just map properly and actually all you need to do is set the .bold flag and it will automatically use the bold version of the font that's embedded. That tells me they're internally linked.

     

    e.g.:

    import flash.events.MouseEvent;

    import fl.text.TLFTextField;

    import flash.text.AntiAliasType;

    import flash.text.Font;

    import flash.text.TextFormat;

     

    var useBold:Boolean = false;

     

    // fonts

     

    var gRegFont:Font = new GRegular();

     

    // handler

     

    stage.addEventListener(MouseEvent.CLICK, handleClick);

     

    function handleClick(e:MouseEvent):void

    {

        useBold = !useBold;

     

        // fix Flash's desire to mass-apply, set twice

        tf.bold = false;

        myTLFTextField.setTextFormat(tf, 0, 16);

     

       // now handle bolding

        tf.bold = useBold;

        myTLFTextField.setTextFormat(tf, 17, myTLFTextField.length);

    }

     

    // TLFTextField init

    var myTLFTextField:TLFTextField = new TLFTextField();

     

    addChild(myTLFTextField);

    myTLFTextField.x = 10;

    myTLFTextField.y = 10;

    myTLFTextField.width = 400;

    myTLFTextField.height = 100;

    myTLFTextField.embedFonts = true;

    myTLFTextField.antiAliasType = AntiAliasType.ADVANCED;

    myTLFTextField.text = "This is my text: This is affected by format";

     

    var tf:TextFormat = new TextFormat(gRegFont.fontName,16,0x0,false);

     

    myTLFTextField.setTextFormat(tf,0,myTLFTextField.length);

     

    I don't even need to set the .font property at all. Internally it's linked and that works fine. I'm not even instantiating the bolded version, it's precompiled and available. I also forgot to set embedFont=true and some antialiasing but it works if you do or don't anyhow.

     

    Edit:

     

    Haha I see you were editing your post too. I think we're both on the same page seeing we said the same exact thing. Although I do need to set the non-bold TextFormat like I did setting from char 0-16 or the entire TextField (or TLFTextField) goes to bold. Setting both formats every time fixes the issue. I don't even need to keep setting a font, it's already saved in the formatting object. I just turn bold on and off.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points