
Код:
function setMaxFontSize (txt:TextField):Number {
var fmt:TextFormat = txt.getTextFormat ();
if (txt.text.length > 1) {
while (txt.maxscroll == 1 && fmt.size < 128) {
fmt.size *= 2;
txt.setTextFormat (fmt);
}
fmt.size /= 2;
var a:Number = fmt.size;
var b:Number = fmt.size * 2;
var c:Number = a + Math.floor ((b - a) / 2);
txt.setTextFormat (fmt);
while (b - a > 1) {
fmt.size = c;
txt.setTextFormat (fmt);
if (txt.maxscroll == 1) {
a = c;
c = c + Math.floor ((b - c) / 2);
} else {
b = c;
c = a + Math.floor ((c - a) / 2);
}
}
fmt.size = c;
txt.setTextFormat (fmt);
}
return c;
}
function sample () {
txt1.text += String.fromCharCode (32 + Math.floor (Math.random () * 60));
trace (setMaxFontSize (txt1));
}
var txt1:TextField = this.createTextField ("txt1", 1, 100, 100, 200, 200);
txt1.border = true;
txt1.multiline = true;
txt1.wordWrap = true;
txt1.text = "";
setInterval(this, "sample", 100);