Quantcast
Viewing all articles
Browse latest Browse all 14

Erratic behavior with Flash’s textWidth property

Image may be NSFW.
Clik here to view.
Just a quick post in case anyone else ever runs into this and manages to find their way to my blog.

I just came across this in a client project I’m working on. I was using a TextField in Flash CS5, and needed to know the width of the actual text inside it for positioning purposes. What I found was that in about 50% of cases, the textWidth property would return zero instead of the strings length in pixels. I tried using autoSize on the TextField and found that it would shorten half of its instances to a single character or less, causing the rest of the line to be invisible.

At first I thought there was something wrong with the font file, but the same happened with Verdana. So I started randomly changing settings, and it turns out that the “anti-alias for readability” setting was causing this. As soon as I changed that setting to “anti-alias for readability” the textfields were being autosized properly, and reported their actual lengths through the textWidth property.

I didn’t really investigate this any further once I found out this workaround. In fact, I needed to use “anti-alias for animation” anyway in my project. Please feel free to comment if this has happened to you, and/or you have more details about this strange little bug.


Viewing all articles
Browse latest Browse all 14

Trending Articles