Posted By

koriner on 02/14/11


Tagged

resize text font as3 autoSize


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

adrianparr
weavermedia
dubogii
merritt212


Auto change text size to fit text field


 / Published in: ActionScript 3
 

  1. function Autosize(txt:TextField):void
  2. {
  3. //You set this according to your TextField's dimensions
  4. var maxTextWidth:int = 145;
  5. var maxTextHeight:int = 30;
  6.  
  7. var f:TextFormat = txt.getTextFormat();
  8.  
  9. //decrease font size until the text fits
  10. while (txt.textWidth > maxTextWidth || txt.textHeight > maxTextHeight) {
  11. f.size = int(f.size) - 1;
  12. txt.setTextFormat(f);
  13. }
  14.  
  15. }

Report this snippet  

You need to login to post a comment.