Flash HTML Textfields – Kick it Old-School

 Apr, 24 - 2009   1 comment   Uncategorized

Most professional-grade fonts don’t register the bold & italic outlines with the same postscript name. For example, “Berthold Akzidenz Grotesk BE”, “Berthold Akzidenz Grotesk BE Bold”, “Berthold Akzidenz Grotesk BE Italic” So to get these to work, you’ve got to either use stylesheets or explicitly set the text to use the correct face.

I updated my portfolio recently, and I didn’t have time to implement a new shell (unfortunately) or code the whole thing over (as much fun as that is). Nor did I feel like tracking down a bug that kept me from publishing the swf to target anything above Flash Player version 6. Yeah, 6.

There wasn’t any StyleSheets class back then. Add to this my crazy text-layout-in-a-circle routine, and adding bold, italic, and link support is an absolute nightmare. But I did it, and now I can show you how.

1st, parse the html as xml and replace the <b> and <i> tags with <font face=””> expressions that will actually target the correct font. I actually wrote a class that lets you map any tag to any other tag.

Next, stick all the html in a temporary textfield and map out where all the TextFormat changes occur. I wrote another class that can compare two TextFormats for equivalence.

My text-in-a-circle code adds words one-at-a-time, effectively creating a custom word-wrap routine. However, I had trouble when I attempted to use a single TextField, so each row uses a separate one. If you’re up to something like this, you have to keep track of how many characters you’ve already used in previous fields. At first, I was getting lots of off-by-one errors and found a carriage-return character (character code 13) kept slipping into my input. Funny, I didn’t put that there…

Flash also doesn’t do a great job rendering things like <b>word</b> <b>second word</b>. It likes to collapse that and the space disappears. I swapped the spaces for non-breaking-spaces (&nbsp;) Feels dirty, but gets the job done.

And remember all those posts about entity problems with HTML coming from XML? The big reason for this undertaking was so I could support links in my portfolio project descriptions. When I linked to google maps, guess what happened to the query parameter ampersands in the href …

The code is so crufty, even I won’t post it. Drop me a line and I’ll send you a private peek.

Related articles

 Comments 1 comment

  • Og2t says:

    Great blog, I find bugs in TextFields quite often as well. You can use condenseWhite = true; to make Flash ignore extra characters and replace &lt;b&gt; with &lt;span class=”strong”&gt;  and add the .strong style to the CSS rather than using &lt;font&gt; tags.


  • Leave a Reply

    Your email address will not be published. Fields with * are mandatory.