dynamic text field bold and italic tags with embedded font problem (flash 8)
Sunday, 23 March 2008
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.
No. 1 — January 6th, 2009 at 11:55 am
Hero!! thank you! this was driving me nuts!
No. 2 — January 6th, 2009 at 12:09 pm
any time!
No. 3 — February 10th, 2009 at 11:47 am
Thanks so much for this help! You rock!
No. 4 — March 24th, 2009 at 3:46 pm
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 “
No. 5 — May 7th, 2009 at 11:40 am
OMG you saved my life like you can’t imagine, I was looking for the solution since monday (currently thursday) !
No. 6 — May 7th, 2009 at 11:45 am
cheers!
No. 7 — September 6th, 2009 at 10:29 am
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!!!
No. 8 — September 7th, 2009 at 5:03 am
Anytime!
No. 9 — September 16th, 2009 at 7:44 am
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
No. 10 — September 16th, 2009 at 7:46 am
(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]“;
No. 11 — September 17th, 2009 at 6:15 am
I’ll take a look as soon as I can. Right now I am busy with soma other project.
No. 12 — September 18th, 2009 at 7:47 am
Thank you, Scuty!
No. 13 — September 18th, 2009 at 8:26 am
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!
No. 14 — September 18th, 2009 at 8:32 am
Ok! Thanks for the tip.
No. 15 — September 29th, 2009 at 5:53 pm
thank you so much for putting this up. it’s the little, undocumented things that were driving me crazy.
No. 16 — October 15th, 2009 at 10:31 am
@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
No. 17 — October 21st, 2009 at 11:11 am
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
No. 18 — October 21st, 2009 at 2:12 pm
@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.
No. 19 — October 22nd, 2009 at 9:02 am
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
No. 20 — October 22nd, 2009 at 9:24 am
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.