I've tried searching for scripts on this subject, but the subject is just too ambiguous. Here's what I'm after:

You (or your designer) has laid out a movieClip with an allocated dynamic textField to be populated with un unknown string. Perhaps the string is going to come from a translation table, or it will be an alert message, or the name of the user.

At runtime, you want the text to be displayed at the largest font size possible, without exceeding the boundaries allocated by the designer. Also, you don't want words to be wrapped mid-word, but (optionally) the string can be wrapped between words.

Ideally, if the designer decides to distort or resize the movieClip (or any parent) that contains the textField, the script will still work. This last criterion may be beyond the scope of MX04, where I've found that the formatting of dynamic text is often compromised when the parent is distorted. Has this been improved in F8?

The basic approach that I've tried is to increase the size of the font one point at a time until it doesn't fit and then decrease it one point at a time until it does fit. The trick seems to be finding a reliable way to test whether or not the "string fits". this test works sometimes, but not always:

stringFits = textField._height <= textField.textHeight && textField._width <= textField.textWidth;

I wonder if the textFormat.getTextExtent() function might work better, but I'm quite fuzzy on its use.

I would really appreciate any help with this problem that anybody would offer. I'm afraid I'm not a very sophisticated AS coder, as I spend the vast majority of my time coding in Director.

Thanks!

Andrew Sinning

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to