5 Replies Latest reply on Aug 13, 2007 11:04 AM by aib42

    TextField.htmlText bug?

      Hi all, I have a TextField that I'm using to display chat messages and stuff. Adding text using .htmlText += "new line" seems to work OK, however look what happens when I remove a line:

      <p>[formatting]<b>nick</b> message1</p>
      <p>[formatting]<b>nick</b> message2</p>
      <p>[formatting]<b>nick</b> message3</p>

      I do:
      var firstLineEnd:int = txtSee.getLineLength(0);
      txtSee.replaceText(0, firstLineEnd, "");

      [line 1 is deleted]
      <p>[formatting]<b>nick message2</b></p>
      <p>[formatting]<b>nick message3</b></p>

      Notice that the end of the <b> tag moves to the end of the line, making the whole thing bold...
      This is AS3.0, but I also have a bug note somewhere about the same problem happening in AS2.0 (The whole textfield suddenly becomes bold)
        • 1. Re: TextField.htmlText bug?
          Juankpro Level 2
          I am writting a similar basic code and I cannot get the error.
          • 2. Re: TextField.htmlText bug?
            kglad Adobe Community Professional & MVP
            i also see no problem.
            • 3. Re: TextField.htmlText bug?
              aib42 Level 1
              Trying to reproduce it for you, I found where the problem was. Here's the code to reproduce the behavior:

              var tf:TextField = new TextField();
              tf.x = tf.y = 0;
              tf.width = tf.height = 300;
              tf.border = true;
              tf.multiline = true;

              var tft:TextFormat = new TextFormat();
              tft.size = 12;
              tft.font = "Verdana";
              tft.color = 0x000000;
              tf.defaultTextFormat = tft;

              tf.htmlText += "<b>aib&gt;</b> line1";
              tf.htmlText += "<b>aib&gt;</b> line2";
              tf.htmlText += "<b>aib&gt;</b> line3";
              tf.htmlText += "<b>aib&gt;</b> line4";
              tf.htmlText += "<b>aib&gt;</b> line5";
              tf.htmlText += "<b>aib&gt;</b> line6";
              tf.htmlText += "<b>aib&gt;</b> line7";
              tf.htmlText += "<b>aib&gt;</b> line8";
              tf.htmlText += "<b>aib&gt;</b> line9";
              tf.htmlText += "<b>aib&gt;</b> line10";
              tf.htmlText += "<b>aib&gt;</b> line11";
              tf.htmlText += "<b>aib&gt;</b> line12";
              tf.htmlText += "<b>aib&gt;</b> line13";
              tf.htmlText += "<b>aib&gt;</b> line14";
              tf.htmlText += "<b>aib&gt;</b> line15";
              tf.htmlText += "<b>aib&gt;</b> line16";
              tf.scrollV = tf.maxScrollV;

              var tt:Timer = new Timer(1000);
              tt.addEventListener(TimerEvent.TIMER, hede);

              function hede(te:TimerEvent) {
              tf.defaultTextFormat = tft; /*********** HERE ***********/
              tf.htmlText += "<b>aib&gt;</b> new line";
              tf.replaceText(0, tf.getLineLength(0), "");
              tf.scrollV = tf.maxScrollV;

              Strangely enough, the first call to hede() behaves as it should. Now, the second call and the ones after that misbehave in different ways according to whether the line marked "HERE" is commented out or not:

              If defaultTextFormat is commented out, then the second and third and fourth... lines added by hede() do not retain the Verdana formatting, they fall back to Times New Roman or whatever the default text is for the textfield...

              If defaultTextFormat is not commented out, however, then every single line on the TextField becomes bold, including those lines that had no bold tag to begin with.

              Weird, eh?
              • 4. Re: TextField.htmlText bug?
                Marghoob Suleman
                Yes i saw that...

                just add a property in your text format.

                tft.bold = false;
                • 5. Re: TextField.htmlText bug?
                  aib42 Level 1
                  That seems to work around the problem, thanks.