A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] TextField width reported incorrectly

  1. #1
    Junior Member
    Join Date
    Jul 2005

    resolved [RESOLVED] TextField width reported incorrectly


    I've been working with a marginally subclassed form of a TextField, which I need to display with embedded fonts. I'm noticing some surprising behaviour with the width property when embedded fonts are enabled, which is causing me trouble further on in my code.

    Due to the way I am animating text, I am displaying each word in a separate TextField (or Word object, as I've subclassed it). I then reassemble a line of text with even spacing, and to that I need to know the width of each word, so that following words will begin at the correct x-position. Before I began to use embedded fonts, the width was reported accurately, as expected, but once I enable embedding, the width property is reported as a much lower value.

    I've included the constructor for my Word object, which shows some traces for debugging, which I've given sample output for below.

    PHP Code:
    public function Word(wText:StringpartOfSpeech:StringchunkTag:String) {
    text wText;
    pos partOfSpeech;
    cTag chunkTag;

    autoSize TextFieldAutoSize.CENTER;
    trace("Pre-scale width: " width);
    trace("Post-scale width: " width);
    this.embedFonts true;
    trace("Post-embed width: " width);

    Example output from three separate words:
    Pre-scale width: 22
    Post-scale width: 45.45
    Post-embed width: 8.450000000000001
    Pre-scale width: 23
    Post-scale width: 47.35
    Post-embed width: 8.450000000000001
    Pre-scale width: 50
    Post-scale width: 71.8
    Post-embed width: 5.800000000000001
    One interesting thing is that for the first two Words listed above, the final width is the same, even though their originating widths vary - while for the third, it begins with a larger width than the first two, but ends up with a shorter one.

    Sorry for such a long post, but I thought I should give some detail. I couldn't find any info on embedded fonts doing this using search engines, but maybe someone has heard of it happening before? Thanks a lot for any help.

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Oregon, USA
    Textfields have a frame which they can render inside of which defines the width - most of the time that frame is invisible. Most likely you want to look at .textWidth instead, which should give you a closer dimension on the actual length of the type inside that field.

  3. #3
    Junior Member
    Join Date
    Jul 2005
    Thanks for the tip; it sounded promising, but unfortunately things are just as bizarre with the textWidth property. I've updated the examples I included with my first post with the textWidth property, which ends up as 0 each time, after embedding is turned on. It also gets very slightly smaller when the overall scale increases. Confusing!

    Pre-scale width: 16; pre-scale textWidth: 12
    Post-scale width: 33.45; post-scale textWidth: 11.9
    Post-embed width: 8.450000000000001; post-embed textWidth: 0
    Pre-scale width: 17; pre-scale textWidth: 13
    Post-scale width: 34.25; post-scale textWidth: 12.350000000000001
    Post-embed width: 8.450000000000001; post-embed textWidth: 0
    Pre-scale width: 36; pre-scale textWidth: 32
    Post-scale width: 50.75; post-scale textWidth: 31.05
    Post-embed width: 5.800000000000001; post-embed textWidth: 0
    I'd love to hear any other ideas. Thank you.

  4. #4
    Junior Member
    Join Date
    Jul 2005
    With your mention of the textWidth property, I thought that the less-common term (in comparison to 'width') would help pin down the issue via Google a little more easily, and so I found a blog post - http://theolagendijk.wordpress.com/2...onts-in-flash/ - which cites the difficulty of getting hold of text width properties.

    I seem to have fixed my problem; it appears I wasn't embedding fonts in the necessary way, even though to all appearances embedding was working correctly. Previously, I'd created a dynamic TextField below the stage, and selected to embed a font into that. Now, I've added the font to the .fla's library, checked the box to export it for ActionScript, and created an instance of it in my Word class, and assigned its name to the font property of the TextFormat object that formats the TextField/Word. Confusing! Hopefully this will help anyone else led here by search engine. And thanks again for the info neznein.

Tags for this Thread

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