dynamic text field bold and italic tags with embedded font problem (flash 8)

I’ve struggled a lot with this problem in the past. So I have decided to assemble a full example for those who are having the same problem. The whole problem is how to add the font names in the library and how to embed fonts for each tag.

So for bold you need to embed the font with the bold check on, for bold and italic check both bold and italic in a separate embed and so on. But nothing is better then an example and source files to better clear this problem as it can be very confusing.

Live example and source files.

Tags: , , , ,

20 Responses to “dynamic text field bold and italic tags with embedded font problem (flash 8)”

  1. Lg3bass writes:

    Hero!! thank you! this was driving me nuts!

  2. scuty writes:

    any time! :)

  3. Gary writes:

    Thanks so much for this help! You rock!

  4. Dan writes:

    simple fix that is not explicitly stated above. Instead of setting the text field like this:
    my_text_field.text = “ info

    simply change it to this:
    my_text_field.htmlText = “ info

  5. GM writes:

    OMG you saved my life like you can’t imagine, I was looking for the solution since monday (currently thursday) !

  6. scuty writes:

    cheers!

  7. Lizard Man writes:

    After all this time here is the solution! I don’t program in Flash very often but when I do this usually causes me headache. Thank you!!!

  8. scuty writes:

    Anytime!

  9. David FF writes:

    This is great – but will it work with an already existing text field in CS4?
    I’m having a great deal of trouble getting multiple embedded font styles to work together in one, already existing text field in CS4.
    I had no problem doing this in CS3 and earlier editions, but it won’t work in CS4…! :-/

    To reproduce:

    1) add an empty, dynamic text field on your stage and name it “myTxt”

    2) Now add four additional text fields on stage and embed uppercase and lower case characters in each. Also, make sure each text field represents a style:
    One bold, one italic, one bold and italic and one regular.

    3) Finally, paste the following code in frame 1:

    myTxt.html = true;
    myTxt.htmlText = “This is a test“;

    This worked like a charm in CS3, but doesn’t work in CS4.
    I would love to adapt your method if it worked on an already existing text field… but does it?

    Please help! :)

    Thanks,
    David

  10. David FF writes:

    (crap it html translated my code… I have now swapped the “” with “[]“:

    myTxt.htmlText = “This [b]is[/b] [i]a[/i] [i][b]test[/b][/i]“;

  11. scuty writes:

    I’ll take a look as soon as I can. Right now I am busy with soma other project.

  12. David FF writes:

    Thank you, Scuty! :)

  13. David FF writes:

    I got your solution to work with an existing text field: you HAVE to preselect the font in this text field (for instance “jester bold”). Then it works.

    Thanks you very much, Scuty!

  14. scuty writes:

    Ok! Thanks for the tip.

  15. gkat writes:

    thank you so much for putting this up. it’s the little, undocumented things that were driving me crazy.

  16. bigE writes:

    @David FF > What do you mean by ‘you HAVE to preselect the font’? I’m having the same problem with one of my projects, it worked before, but now, when I republish in CS4, it doesn’t work anymore :(

  17. magicGea writes:

    I am struggling with this problem since few days, your example was really helpful but my project still won’t display bold and italic.
    I got this dynamic scrolling text field that loads external txt file (HTML formatted). The moment I embed the font I don’t see bold nor italic, other tags like links, underline, font color works no problem.
    So I managed to figure out that I am missing something while embedding, I followed your example but it still doesn’t display me correctly – I think my action script is missing something.
    Could you take a look?
    -MY FONTS
    Helvetica Neue:
    EastA 55 Roman
    EastA 75 Bold
    EastA 55 Roman Oblique
    - I embedded them in the library as Font1, Font2, Font3
    - My AS is:
    txtBox.autoSize = “left”
    txtBox.htmlText = myVars.txt;
    txtBox.setTextFormat(txt);
    myVars = new LoadVars()
    myVars.onData = function(data){
    txt = data
    trace(data)
    embedFonts = true;
    html = true;
    }
    myVars.load(“olaf.txt”)

    I don’t know where and how to say in AS (if you see in olaf.txt file something display it with Font2!!!!!! etc)

    Please help
    Thank you
    Magic

  18. scuty writes:

    @magicGea

    You don’t have to specify the font, flash does that for you. All you need is to embed the fonts separately with all the combinations (normal, bold, italic, bold and italic) and different names. I am not 100% sure if naming have any impact on how the text shows.

    If you have an text box on the stage then you have to go and embed the font manually for the text box. Remember that this has nothing to do with the fact that you added the font in your library so you still have to select the font to embed for the text box.

    I am not really sure what do you want to do with this:
    myVars = new LoadVars();
    myVars.onData = function(data) {
    txt = data;
    trace(data)
    embedFonts = true;
    html = true;
    }
    myVars.load(“olaf.txt”);

    This lines can be set on the text box properties (so you don’t need them):
    embedFonts = true;
    html = true;

    I don’t know what is this:
    txt = data;
    But if you want to set the text then you should do this:
    txtBox.htmlText = data;
    and this must be inside your onData function, so this: txtBox.htmlText = myVars.txt; does not make a lot of sense.

    Hope that was helpful.

  19. magicGea writes:

    Thank you for your reply
    I have to say I don’t understand everything in this code myself, it’s a part of AS associated to text box in my scroll text box that I downloaded from internet.
    I did embed the font for the text box – and when I did that it stopped displaying bold and italic (it displays me only the character that is embedded for this particular text box)(I embedded italic and bold characters as well in other text boxes)

    Any clue?
    Thank you

  20. scuty writes:

    So you have the font in you library as normal, bold, italic and bold-italic. This is the key, to have the font in you library 4 times and:
    - for one font don’t check anything (this is the normal font)
    - for one font check just the bold
    - for one font check just italic
    - for one font check both bold and italic

    If you do that that you should be fine. Also I’m not sure about the selected font in your text box. Try both the font in your library and the actual font name from your machine. I forgot how that is done. But it would make more sense to embed the font from your library.

    Try that and let me know.

Leave a Reply


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

for better code support use: <pre lang="the_language">
where "the_language" can be: actionscript, actionscript3, php, java etc.