Skip to main content
Inspiring
January 18, 2012
Answered

Autoresize text size in textfield

  • January 18, 2012
  • 1 reply
  • 481 views

Hi,

I have a highscore-list on my upcoming game (Flash cs 5.5)

I've made textfields (drawn from the gui).

Names on the highscore-list can be up to 20 chars. But if one is written with uppercase-letters, the text won't fit into the textfield.

I've tried some samples on the net, but I didn't get them to work.

I had this code earlier, but it would be great to use max font size on each highscore-name.

hs_1.setTextFormat(myformat);

if(countUpperCaseChars(hs_2.text)>12)
{
myformat.size = 15;
}
else
{
myformat.size = 18;
}

Any tip?

Dan

This topic has been closed for replies.
Correct answer gronli21

Got it finally to work with this:

hs_1.autoSize=TextFieldAutoSize.LEFT;

myformat.size=50;

while (hs_1.textWidth > 320) {

myformat.size--;

hs_1.setTextFormat(myformat);

  }

case closed

1 reply

gronli21AuthorCorrect answer
Inspiring
January 19, 2012

Got it finally to work with this:

hs_1.autoSize=TextFieldAutoSize.LEFT;

myformat.size=50;

while (hs_1.textWidth > 320) {

myformat.size--;

hs_1.setTextFormat(myformat);

  }

case closed