This is a pretty common problem with Flash (not being able to set line height and or letter spacing on dynamic text fields), and I am sure some of you have found good work arounds for this, but I figured I would post mine for giggles and you know what.
This is using instance names from the Nike Golf banner I am working on:
function setTextFormatting(){
var fmt:TextFormat = club_name.name.getTextFormat();
club_name.name.setTextFormat(fmt);
club_name.name.setNewTextFormat(fmt);
club_name.name.autoSize = "left";
}
Basically, just put text in the box that represents either the letter spacing, or line height (i.e. generate two lines, or at least two characters), grab it as a TextFormat, then set it and then RE set it as a new format for the box you want to control.
It’s silly, but it works.
UPDATE:
Apparently this solution doesn’t work for everyone. The linked blog post describes 3 solutions to this problem that don’t work for him. I find it telling (this is Dru, by the way, not the original author of this post) that solutions 2 and 3 are essentially the same thing. But it’s worth noting a few observations.
For one, this post is all about AS2. But the problem still seems to be present in AS3. An updated version of the solution is this:
var tf:TextFormat = t.getTextFormat();
t.defaultTextFormat = tf;
t.htmlText = "Bob Loblaw";
Where “t” is an existing TextField. It’s a little nicer than having to set the TextFormat twice, but still, kind of a hassle. If you’re doing a lot of this, you might want to extend TextField and take care of the formatting business in the constructor, so long as you can live with dynamically created TextFields.
If you find you have to use the solution advanced by Joe Wong, you may wish to consider the use of a StyleSheet to make application of the letterSpacing a little easier.
var s:StyleSheet = new StyleSheet();
s.setStyle("spaced", {letterSpacing:30});
t.styleSheet = s;
t.htmlText = "<spaced>Bob Loblaw</spaced>";
Obviously you can work with the styles however you wish, and you can also apply the custom-TextField-extension idea to this, as well.

2 comments
Comments feed for this article
April 9, 2009 at 10:42 pm
motou
Thanks for the update. It’s also interesting to see a bug issue which was reported to adobe:
http://bugs.adobe.com/jira/browse/FP-77
and there is still no answer or solution at all.
October 13, 2009 at 6:50 pm
kinoli
Easiest solution is to just wrap a textformat tag around your text with leading property. I’ve also made a text creation class to allow me to put the leading attribute in my css doc and just look for any css attribute called leading, in which case I will automagically wrap the text in the textformat class with leading applied. Makes things super easy come time to use text.
line oneline two