Click to See Complete Forum and Search --> : [Resolved] [Resolved] FONT WIDTH CHARACTER

03-13-2001, 02:57 PM

I want to know the width of a specified font character. Do you know a method to get it ?

The method used by Pavils Jurjans isn't very simple. Do you known another method do do it ?


02-21-2002, 07:20 PM
I moved this post to one of the help forums (http://board.flashkit.com/board/index.php?categoryid=2), because you'll get help there. The Boardroom (where you originally posted) is reserved for discussing topics about business and the industry.

Thank you.


03-12-2003, 08:23 AM
Hi there,

Make a textfield and give it the intancename 'mytext'. Select whatever font from which you want to get the character widths.
In the characters menu select 'Embed font outlines for: All characters'.

fontWidths = new Array();
//this will contain an array of the width of each character
myText.autoSize = "left";
textfieldmargin = 4 // 2 pixels margin on both sides off the character

myText.text = String.fromCharCode(i)
chrWidth = myText._width;
// if the textfield has margins use this code
// chrWidth-= textfieldmargin;

Neat huh ;)

06-05-2003, 02:24 AM
I notice the above example uses "myText.autoSize"... that's an MX only function. I'm using Flash 5 (and hopefully publishing to Flash 4 .swf)... Does anyone know a way to do this in earlier versions of Flash?


06-05-2003, 02:47 AM
I wouldn't advise kerning unless the text is unusually displaced.
As it causes anti aliasing issues.

There are several mono space fonts available however.

But I really find them a waste of effort.

06-05-2003, 07:10 AM
I have tried the code you gave but it give each char the same width?

06-05-2003, 07:14 AM
sounds strange ...
are you sure you're not using a monospaced font?

06-05-2003, 09:47 AM
yes definately not using a monospaced font,

found an fla that has simalar acion script in but still can get it to work. I am trying to create a dynamic text scroller and have tried lots of variations to get the width of the latest char but not working

duplicateMovieClip("char", "char" add i, i);
set("char" add i add "/letter:char", substring(text, i, 1));
thewidth = (["char"+i])._width;

06-09-2003, 09:09 AM
still giving the same width for all text items and have tried a load of dirrerent fonts,

Does anyone have any ideas


06-09-2003, 10:05 AM
Hi there,

I'm sorry ... like 'dc4everyone' said
"myText.autoSize"... that's an MX only function

It is only possible from flash 6+.

If you can make an array in flash 4 (I don't know) you could stores the values in a array - but you'd have to measure the character sizes the hard way :o


06-09-2003, 10:31 AM
im using flash 6 but still cant get the example you gave or my own code to work???

06-09-2003, 10:45 AM
why the heck are you using f4 syntax. My code works perfectly the way it is ;)

Are you sure youre working with the textfields instance name instead of the variable name?

*btw - when using flash4 or flash5 instead of measuring the hard way - you could off course use the function in flash6 and paste the traced values into your array*

Are you in desperate need of a sample file here? ;)


06-09-2003, 11:06 AM
Cheers for the help, got it sorted in the end was mixing text field + instance names up.

The flash 4 syntax is becasue I am creating a flash file from an old text tutorial and had left as it was.


06-09-2003, 11:07 AM
glad we sorted it out!