Tuesday, January 16, 2007

Flash/Flex TextField Bug - Dancing FlashType Characters

I just discovered this TextField bug today and wanted to get a demo of it out there. Basically, there are certain whitespace characters which are not properly handled by Flash TextFields. If you're not aware of them, they can really leave you scratching your head. One thing they can do is throw off the text metrics returned by methods such as getCharBoundaries, making them wildly unpredictable. A more visible symptom of these characters is text that expands, wiggles and reflows every time you make a selection or click within the TextField.

Check out the demo, and the mxml used to make it. To replicate the issue in the top TextArea, click in the white space to the left of a line of text, and then drag right to select. You should see the text wriggle and jump around like me after a six pack. Notice the bottom TextArea doesn't have the problem, because it doesn't use FlashType.

The character codes that can cause the anomolous behavior are:
11,12,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,30,31, & 160.

Most of these characters will never be a problem, because they're seldom encountered in the wild. However, 160 is frequently seen in its other form: - the non-breaking space.

To work around this issue, I'll be pre-processing all HTML that comes into Flash by stripping out all those characters and replacing them with regular old spaces, which don't have the problem.

Was this post helpful to you? If so, please consider making a small donation to keep this blog going.

4 Comments:

Anonymous Anonymous said...

I'm not seeing it, Camino 1.1a2+, Flash 9, OS X. What is FlashType?

10:05 AM  
Blogger tom said...

Hi Mark! FlashType is what Adobe is calling Flash's advanced antialiasing feature these days. I'm not sure when they started calling it that - the first time I saw it was in the Flex 2 documentation.

I'm seeing the issue in Camino on my PowerPC Mac. Didn't check Camino on my Intel Mac, although I did check Firefox. I have the latest Flash player.

10:34 AM  
Anonymous Anonymous said...

Okay, I installed the latest version and the bug shows up. Seems to be a bug in the Flash player.

By the way, how are you embedding the nbsp character? I can't get it to work!

11:29 AM  
Blogger tom said...

I'm actually not embedding the nbsp character: I'm just putting the entity in my html string.

I did try embedding the character by specifying it in the unicode-range property for that font, but it didn't affect the demo. I'm honestly not sure it's possible to embed the nbsp.

12:56 PM  

Post a Comment

<< Home