Hi,
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 ?
Bernard.
Printable View
Hi,
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 ?
Bernard.
I moved this post to one of the help forums, because you'll get help there. The Boardroom (where you originally posted) is reserved for discussing topics about business and the industry.
Thank you.
-scott
http://www.scottmanning.com
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'.
Neat huh ;)Code: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
for(i=0;i<255;i++){
myText.text = String.fromCharCode(i)
chrWidth = myText._width;
// if the textfield has margins use this code
// chrWidth-= textfieldmargin;
fontWidths.push(chrWidth);
}
trace(fontWidths);
//pod
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?
Cheers!
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.
I have tried the code you gave but it give each char the same width?
sounds strange ...
are you sure you're not using a monospaced font?
//pod
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
Code:duplicateMovieClip("char", "char" add i, i);
set("char" add i add "/letter:char", substring(text, i, 1));
thewidth = (["char"+i])._width;
trace("thewidth="+thewidth);
still giving the same width for all text items and have tried a load of dirrerent fonts,
Does anyone have any ideas
??
Hi there,
I'm sorry ... like 'dc4everyone' saidIt is only possible from flash 6+.Quote:
"myText.autoSize"... that's an MX only function
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
//pod
im using flash 6 but still cant get the example you gave or my own code to work???
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? ;)
//pod
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.
Cheers:)
glad we sorted it out!
//pod