2 Replies Latest reply on Apr 23, 2010 4:11 AM by Harry Kunz

    Dynamically size a text field???


      What is the best way to dynamically size a text field?

      I've been able to size the width (probably not the best way), but how about the height?  What variable can I use to find the number of lines used in a text field?


      This is what I've got so far.

      thanks in advance


      var my_str:String = "Small string";


      // Create a TextFormat object,
      // and apply its properties.
      var my_fmt:TextFormat = new TextFormat();
      with (my_fmt) {
          font = "Arial";
          bold = true;


      // Obtain metrics information for the text string
      // with the specified formatting.
      var metrics:Object = my_fmt.getTextExtent(my_str);


      // Create a text field just large enough to display the text.
      this.createTextField("my_txt", this.getNextHighestDepth(), 100, 100, metrics.textFieldWidth,
      my_txt.border = true;
      my_txt.type = "input";
      my_txt.wordWrap = true;
      my_txt.multiline = true;
      // Assign the same text string and TextFormat object to the my_txt object.
      my_txt.text = my_str;




          my_txt._width = my_txt.length*(0.7*my_fmt.size);
          //my_txt._height = my_txt._height+1;
          trace(my_fmt.size = 12);