A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: [RESOLVED] Truncate Text in Dynamic Text Field?

Hybrid View

  1. #1
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    The x and y are the position from the left upper corner of the textfield. There will always be a letter or space in case there is no letter and it is a fixed position in the textfield. You can get a longer string by getting the letters before or after the position using the text in the textfield as the starting string.
    - The right of the People to create Flash movies shall not be infringed. -

  2. #2
    Senior Member
    Join Date
    Jan 2006
    Posts
    133
    hmmm, I'm sorry, I'm not following or I might not have communicated what I'm trying to do properly.

    I have a text field on stage with a given width and height.
    I need to be able to populate that text box with a variety of text strings.... such as a movie title. Then, once the string is in there, (or before I populate the TextField with the string) I need to truncate it.

    SO, if the movie title is "Gamer"... no truncation needed. However, if the movie title is "The Assassination of Jesse James by the Coward Robert Ford"... I'm going to need to truncate the title properly.

    You say that "There will always be a letter or space in case there is no letter and it is a fixed position in the textfield"
    I don't see how that is true, please explain.

    If this is my text field, where "x" is the arbitrary 300, 40 point you just defined:

    Code:
    +---------------------------+
    |                           |
    |                         x |
    +---------------------------+
    If the title is "Gamer", the field will look like this:

    Code:
    +---------------------------+
    | Gamer                     |
    |                         x |
    +---------------------------+
    getCharIndexAt("x point") will return as "-1" telling me there is no character there... whitespace or otherwise, so truncation is not needed.

    However, now I change the text via AS3 to "The Assassination of Jesse James by the Coward Robert Ford".

    If the text field looked like this:

    Code:
    +------------------------+
    | The Assasination of    |
    | Jesse James by the Cow |
    +------------------------+
    ard Robert Ford                <--- below the fold text
    Testing the "x point" would be fine, because it would return the index of the letter "w" in the word "Coward".
    However, that's not how Flash wraps words, so in reality the text field would look like this, because Flash won't hyphenate "Cow-ard", so it puts the entire word on the next line, which extends "below the fold":

    Code:
    +-------------------------+
    | The Assasination of     |
    | Jesse James by the    x |
    +-------------------------+
    Coward Robert Ford          <--- below the fold text
    So testing the "x point" would return as "-1", but I still need to truncate the title, so choosing an arbitrary point doesn't help... unless I'm completely missing something?
    Last edited by badaboom55; 02-25-2010 at 04:26 PM.

  3. #3
    Senior Member
    Join Date
    Jan 2006
    Posts
    133
    To clarify further... I would want the text box to look like this:

    Code:
    +-------------------------+
    | The Assasination of     |
    | Jesse James by the ...  |
    +-------------------------+
                                        <--- NO BELOW THE FOLD TEXT
    Although, I suppose if I absolutely couldn't get the above, this would be acceptable as well, although, I fail to see how this would be possible and the above wouldn't:

    Code:
    +-------------------------+
    | The Assasination of     |
    | Jesse James by the ...  |
    +-------------------------+
     Coward Robert Ford        <--- below the fold text

  4. #4
    Senior Member
    Join Date
    Jan 2006
    Posts
    133
    I swear to all that was mighty, that this wasn't working when I posted... now it is!

    Ok, anyway, if this is the text box:

    Code:
    +-------------------------+
    | The Assasination of     |
    | Jesse James by the      |
    +-------------------------+
    Coward Robert Ford          <--- below the fold text
    First I get the text from the last line, using bottomScrollV, and if then I can replace the last word/whitespace character with "..." and then append that to the end of the first line

    In short:

    PHP Code:
    var LastLineText_str:String myTextField.getLineText(myTextField.bottomScrollV 1);

    // this gets me "Jesse James by the " in a string
    // Then just run an operation to replace "the" or the " " character with an ellipse 

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