Return to Snippet

Revision: 41212
at February 14, 2011 09:23 by koriner


Initial Code
function Autosize(txt:TextField):void 
{
  //You set this according to your TextField's dimensions
  var maxTextWidth:int = 145; 
  var maxTextHeight:int = 30; 

  var f:TextFormat = txt.getTextFormat();

  //decrease font size until the text fits  
  while (txt.textWidth > maxTextWidth || txt.textHeight > maxTextHeight) {
    f.size = int(f.size) - 1;
    txt.setTextFormat(f);
  }

}

Initial URL

                                

Initial Description

                                

Initial Title
Auto change text size to fit text field

Initial Tags
resize, text

Initial Language
ActionScript 3