1 Reply Latest reply on Jan 8, 2009 2:31 AM by RUSH-ME

    Truncate text?

    Handycam Level 1
      I have a text area that is updated with a node in an XML dataset based on the selected item of a list (tl):

      <mx:TextArea id="caption" text="{tl.selectedItem.caption}" />

      My problem is sometimes this text will not fit into this area in the layout. I would like to clip this text to a maximum character count that does fit. so I created a function:

      public const maxCount:uint = 365;

      private function truncateText(s:String):String {
      if (s.length > maxCount) {
      s = s.substring(0,365);
      s = s + "...";
      }
      return s;
      }

      But I am unsure if this is the best way, or even how to assign this function directly to the text field so that it is applied each time the user makes a new selection in the list "tl".

      Thoughts?
        • 1. Re: Truncate text?
          RUSH-ME Level 3
          Hi

          Add that function at "change" event
          like
          <mx:TextArea id="caption" change="truncateText(caption.text)"/>

          In that function instead of returning the string assign it to the text of your textarea.
          otherwise you can add that function to the list's change event.

          Hope this will help you.