views:

580

answers:

2

In actionscript 3, my TextField has :

  • CSS styling
  • embedded fonts
  • textAlign : CENTER
  • autoSize : CENTER

... when italics are used the very right character gets slightly cut off (specially caps). It basically seems that it fails detecting the right size.

I've had this problem before but just wondered is there a nice workaround (instead of checking textWidth or offsetting text etc.)?

A: 

I've had issues with TextField masks behaving differently in the Flash preview, and in the actual browser plugin. Usually, and this is strange to me, it would appear more correctly in the browser. Have you tried running the swf in a browser to see if the problem is actually an annoyance rather than a permanent problem?

I had said this:
My in-ideal approach to solving this is to attach a change event to the TextField which always adds a space after the last character of the field. And then to remember to trim this space off when using the value.

But that didn't take into account that this probably doesn't have a change event and that it's an HTML rendered text field. To add a trailing space in the HTML text field throw in an   again, that's not really fixing the problem.

dlamblin
Thanks for your input. It's not an input fields though. Adding spaces doesn't work since white spaces are trimmed if the textField is used with HTML.
Theo.T
+1  A: 

Not that it is much comfort to you, but Flash sometimes has trouble with this seemingly simple task. CSS styling of html TextField was a nice addition but it has caused headaches for text-rendering. In fact I very rarely use CSS for styling text for that reason. I can only imagine that combining bold, italic and normal type faces within the HTML causes Flash to get some of the width calculations wrong which causes autoSize to set the mask a tiny bit short. I hope very much that the new text rendering engine in Flash Player 10 will finally fix these issues (it certainly looks better in theory).

So my solution is never to use HTML with the exception being when I require <a> links in my text ... and there are even some tricky text shifting issues there. In those cases I avoid mixing different font weights and font styles within the same text field. All other cases I use TextFormat directly on TextField.

I suppose if you can't get out of your current architecture (for some reason) you could try adding &nbsp; to the end of your html encoded strings. Or you could manually set the width of the field and not rely on autoSize (as you have mentioned). But if you keep on the CSS/HTML route you may find another new and painful limitation just when you don't want it.

James Fassett
Thanks for the link to the FTE. Something to look into for sure. TextFields are currently a total pain in my ass and I'm glad that there's an alternative.
Chuck Vose