Skip to main content
October 3, 2007
Answered

Shorten a string before placing in a dynamic text field

  • October 3, 2007
  • 2 replies
  • 487 views
I am creating buttons with dynamic text fields I am filling from an array. The problem is some of the array elements are too long to fit and overflow out of the button.

Is there an easy (or complicated for that matter) way to go about shortening any that are longer then say 30 characters to 27+"..."?

Thanks.
This topic has been closed for replies.
Correct answer AScracker
Hi
you can use this code....
var str:String = "length of string 27 display 30"
trace(str.length+"---> length of the word");

trace(str.substr(0,27)+" ---> 27 words");
trace(str.substr(0,30)+" ---> 30 words");

~~SK

2 replies

October 3, 2007
Thanks, works perfect!
Inspiring
October 4, 2007

you are welcome
~~Sk
AScrackerCorrect answer
Inspiring
October 3, 2007
Hi
you can use this code....
var str:String = "length of string 27 display 30"
trace(str.length+"---> length of the word");

trace(str.substr(0,27)+" ---> 27 words");
trace(str.substr(0,30)+" ---> 30 words");

~~SK