A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] Finding the size of a text box

  1. #1
    Musical chair sumwungye's Avatar
    Join Date
    Jan 2008
    Location
    Planet Earth, third planet from the Sun
    Posts
    287

    resolved [RESOLVED] Finding the size of a text box

    So, I have a dynamic text box, which, naturally, being dynamic, changes.

    What I would like to figure out is how to tell when the changing text is larger than the textbox holding it.

    Of course, just because it is a certain number of characters long doesn't mean it will be larger than the textbox holding it. Twenty of the letter "w" is larger than twenty of the letter "i"

    So, is there a way to tell if the textbox isn't large enough to hold its text?

    Thanks
    --SumWunGye

  2. #2
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    Make the text box a set size, assign the text to it, and check the maxscroll. If maxscroll equals one, the text fits in the textbox.

  3. #3
    Senior Member
    Join Date
    Oct 2008
    Posts
    227
    You could also try textWidth function.

    if(textBox.textWidth > textBox._width){
    trace("Text is wider than the holder");
    }

    Have never tested that function, but it should work.

  4. #4
    Musical chair sumwungye's Avatar
    Join Date
    Jan 2008
    Location
    Planet Earth, third planet from the Sun
    Posts
    287
    Thanks, guys, for responding.

    Sorry, I forgot to mention this is a multiline textbox.

    For some reason, textBox.textWidth and textBox.textHeight (height being what I need) are undefined when I trace them.

    And I would use maxscroll, but, with what I'm doing, my text's font will get smaller when the text doesn't fit in the textbox. So, maxscroll changes variably.

    But, if I figure out how to make textHeight work, I think this will work.

    Thanks again!
    --SumWunGye

  5. #5
    Musical chair sumwungye's Avatar
    Join Date
    Jan 2008
    Location
    Planet Earth, third planet from the Sun
    Posts
    287
    And, I also found out it's only undefined when I use actionscript to change what it says.

    PHP Code:
    textBox "Hello.";
    //or
    textBox="HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello."
    Either one of these lines of code being put before the trace(textBox.textHeight); makes it undefined, which is weird.

    Any idea why?
    --SumWunGye

  6. #6
    Musical chair sumwungye's Avatar
    Join Date
    Jan 2008
    Location
    Planet Earth, third planet from the Sun
    Posts
    287
    Okay, I figured it out. For some reason, you need to add ".text" to the end of the textbox's variable name.

    PHP Code:
    textBox.text "Hello..."
    --SumWunGye

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