2 Replies Latest reply on Apr 5, 2008 11:29 AM by Newsgroup_User

    Add text to text member, retain formatting

    Level 7
      I have a script that formats each line of a text member, setting various
      properties like the font, fontsize, color, etc. Basically it's a chat
      window that allows the user to format messages from others users in
      order to make it easier to read. Example, messages from Bob are in red,
      message from Bill are blue, italics, etc.

      As new messages arrive, they are appended to the end of the members text.

      Member("ChatWindow").text = Member("ChatWindow").text & RETURN & "Some
      new text"

      This wipes out the individual line formatting, returning everything to
      the default font, color, etc. I prefer to avoid having to go line by
      line, resetting the customized line properties each time a new message
      is received. So is there a way to add to the text without losing the
      customized line settings?
        • 1. Add text to text member, retain formatting
          Chunick Level 3
          use the undocumented .setContentsAfter() or .setContentsBefore()

          what I did for a chat program I wrote was get the line count before adding the line and then formatting the text how I wanted after adding the line - the reasoning was that I allowed a user to enter multiple lines using Shift+Enter key (like MSN messenger) and the user's username and maybe the post time would be prepended to what they typed, so it would not work getting the line count after the fact.. this gave me a bit more formatting control, which I wanted.

          lineCount = member("ChatWindow").line.count
          member("ChatWindow").setContentsAfter(RETURN & "Some new text")
          endLineCount = member("ChatWindow").line.count
          member("ChatWindow").line[lineCount + 1].fontStyle = [#italic]
          member("ChatWindow").line[lineCount.. endLineCount].color = color(255,0,0)

          • 2. Re: Add text to text member, retain formatting
            Level 7
            Perfect. Many thanks. I think I will also include your Shift+Enter