3 Replies Latest reply on Jul 7, 2009 11:27 AM by Flex harUI

    Splitting text across multiple TextAreas

    fischbjoernchen

      Hello,

       

      I'd like to create a Flex component with a htmlText property that distributes the text evenly on several TextAra or Text components. I've found a solution for pure Flash TextField here: http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Liv eDocs_Parts&file=00000240.html

       

      But that uses the numLines property which isn't available in TextArea. I've tried to subclass Text and use the internal textField property to get the remaining text but that didn't work. The debugger shows that numLines is 1 (when called from the commitProperties method of the conatining class). Here is my code for a single text:

       

      public class CutText extends Text
          {
              public function doTextCutting():String
              {
                  var field = textField;
                  var linesRemaining:int = field.numLines;
                  var linesVisible:int = field.numLines - field.maxScrollV + 1;
                 
                  var fieldText:String = "";
                  var remainder:String = "";

                  for (var j:int = 0; j < linesRemaining; j++)
                  {
                      if (j < linesVisible)
                      {
                          fieldText += field.getLineText(j);
                      }
                      else
                      {
                          remainder +=  field.getLineText(j);
                      }
                  }
                 
                  field.htmlText = "<p>" + fieldText + "</p>";
                  return remainder;
              }
          }

       

      here is the commitProperties code of the component that distributes the text on its CutText children:

      override protected function commitProperties():void
              {

                  var remainder:String = this.htmlText;

                  for(var i:int = 0;i<numChildren;i++)
                  {
                      var child:DisplayObject = getChildAt(i);
                      if(child.name.substr(0,4) == "text")
                      {
                          var myText:CutText = CutText(child);
                          myText.htmlText = remainder;
                          remainder = myText.doTextCutting();

                      }

              }

      }