Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Getting width of dynamic text boxes containing different letters

New Here ,
Mar 02, 2013 Mar 02, 2013

I have dynamic text boxes next to each other, each showing a letter and creating a word, any letter of English ABC. Since some letters are wider, how could I get the width of each letter to figure out spacing between them?

Thanks!!

TOPICS
ActionScript
846
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 02, 2013 Mar 02, 2013

You can use the textWidth property of the textfield to get the width of the text inside it.

Translate
LEGEND ,
Mar 02, 2013 Mar 02, 2013

You can use the textWidth property of the textfield to get the width of the text inside it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2013 Mar 02, 2013

Thanks! Works prefectly!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2013 Mar 02, 2013

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 02, 2013 Mar 02, 2013

I must add I got the textWidth work, came up with a simple formula to place the letters at an even distance, but still, some letters like capital W and P need less space after them to look nice. The second letter can be closer to them. No big deal, can be solved with an if statement, leave less space in case those letters are capitalized.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 02, 2013 Mar 02, 2013

Yep, some letters are not evenlt spread across their width, especially so with variable width fonts.  If you were to use a fixed width font you, like Courier, you would probably not have as much of an issue.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2013 Mar 03, 2013
LATEST

Thanks for the info Ned, very useful as always.

My little Flash project is going to be used by children, this is why I've been using Comic Sans. This is one of the few fonts that uses single-story letter "a".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines