dcsimg
A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: [Resolved] [Resolved] FONT WIDTH CHARACTER

  1. #1
    Junior Member
    Join Date
    Mar 2001
    Posts
    1
    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.

  2. #2
    Moderator
    The Minister of No Crap

    Join Date
    Nov 2000
    Location
    Philadelphia
    Posts
    2,685
    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

  3. #3
    Bob (the singing sock)
    Join Date
    Aug 2000
    Location
    Århus, Denmark
    Posts
    472
    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'.
    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);
    Neat huh
    //pod

  4. #4
    Junior Member
    Join Date
    Jun 2003
    Posts
    2
    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!

  5. #5
    Flashkit historian Frets's Avatar
    Join Date
    Oct 2000
    Location
    flashkit
    Posts
    8,797
    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.

  6. #6
    Hammer
    Join Date
    Mar 2001
    Location
    Warrington UK
    Posts
    274
    I have tried the code you gave but it give each char the same width?

  7. #7
    Bob (the singing sock)
    Join Date
    Aug 2000
    Location
    Århus, Denmark
    Posts
    472
    sounds strange ...
    are you sure you're not using a monospaced font?
    //pod

  8. #8
    Hammer
    Join Date
    Mar 2001
    Location
    Warrington UK
    Posts
    274
    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);

  9. #9
    Hammer
    Join Date
    Mar 2001
    Location
    Warrington UK
    Posts
    274
    still giving the same width for all text items and have tried a load of dirrerent fonts,

    Does anyone have any ideas

    ??
    Attached Files Attached Files

  10. #10
    Bob (the singing sock)
    Join Date
    Aug 2000
    Location
    Århus, Denmark
    Posts
    472
    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

    //pod

  11. #11
    Hammer
    Join Date
    Mar 2001
    Location
    Warrington UK
    Posts
    274
    im using flash 6 but still cant get the example you gave or my own code to work???

  12. #12
    Bob (the singing sock)
    Join Date
    Aug 2000
    Location
    Århus, Denmark
    Posts
    472
    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

  13. #13
    Hammer
    Join Date
    Mar 2001
    Location
    Warrington UK
    Posts
    274
    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

  14. #14
    Bob (the singing sock)
    Join Date
    Aug 2000
    Location
    Århus, Denmark
    Posts
    472
    glad we sorted it out!

    //pod

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center