A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Text / String Gods, hear my plea!

  1. #1
    HELP>>>ACTIONSCRIPT DICTIONARY
    Join Date
    Feb 2000
    Location
    In the Present Moment
    Posts
    1,041

    Text / String Gods, hear my plea!

    I have a dynamic text field that I need to do some special formatting on the text that it contains. I need to be able to grab the first line of text (however many characters that that ends up being when the actual text populates) and change its color to red and bold face it. Then I need to format the rest of the text to be non-bolded black.

    My questions are as follows:

    1) How do I detect what text/how many characters appear on the first line in any given dynamic text field? (The answer to this question being the most important part of my puzzlement.)

    2) What do I use to grab that text?

    3) How do I format that bit of text to my "highlighted" colors and then use a second format on the rest of the "non-highlighted" text?

    Questions 2 and 3 will be relatively non-issues if question 1 can be answered successfully, I included them so as to expand the scope of the project that I am working on for your excellent assistance. (Feel free to advise me on how you might do 2 and 3 too. I'm all for new ideas and I am pretty new to doing extensive string and textfield manipulation.)

    I'm a very experienced AS programmer so just lay your wisdom on me, if you please. I'll leave an offering at your altar.

    Any and all help is greatly appreciated. Thank you for your time.
    Antibody
    "Our deepest fear is not that we are inadequate.
    Our deepest fear is that we are powerful beyond measure." - N. Mandela

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Assuming you entered the text using the Flash authoring system, then the lines are going to be delimited by the carriage return character ("\r").

    Let's say your text field is called my_text.

    To find the end of the first line, you can use this:

    var lengthOfLine1 = my_text.text.indexOf("\r");

    If lengthOfLine1 is -1, then there is only one line. Otherwise, lengthOfLine1 is the same as the length in characters of the first line. You can then use various forms of subStr to extract either line1 or the remaining lines.

    var line1 = my_text.text.substr(0,lengthOfLine1 );

    ...

    Oh yes, and to see some truly studly text-processing, see my new movie, "Psychoanalysis with Sigmund Freud" - at the bestiary link below.

    - Jim

  3. #3
    HELP>>>ACTIONSCRIPT DICTIONARY
    Join Date
    Feb 2000
    Location
    In the Present Moment
    Posts
    1,041
    Thank you for your reply. I shall try that solution out for sure.

    The text that I will be using is generated on the fly from a database, so do you suppose your solution might still work?

    I don't have my project with me at home, but I will make a demo here at home.

    Thanks again.
    Antibody
    "Our deepest fear is not that we are inadequate.
    Our deepest fear is that we are powerful beyond measure." - N. Mandela

  4. #4
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Most likely it will work. If it doesn't, and you see (using trace) that indexOf() is returning -1 (meaning it can't find the "\r"), then try replacing the "\r" (carriage-return) with a "\n" (line-feed).

    Depending on how the text is generated, one of those two characters, carriage-return or line-feed, will be used to separate the lines.

    - Jim

  5. #5
    HELP>>>ACTIONSCRIPT DICTIONARY
    Join Date
    Feb 2000
    Location
    In the Present Moment
    Posts
    1,041
    Excellent, thank you kindly. I'll try it out after dinner then.

    BTW the text will just be a Response.Write vomit as in:

    &headlines=A lot of text that is put in there to say something cool about the content of this particular site. Clients are weird that they want to say cool things about their particular interests. :O&nextVar=blahblahblah

    or something like that
    Antibody
    "Our deepest fear is not that we are inadequate.
    Our deepest fear is that we are powerful beyond measure." - N. Mandela

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