2 Replies Latest reply on Jul 31, 2009 7:13 AM by Gregory Lafrance

    Performance Issue with calling setTextFormat() over and over... Need to temporarilly disable redraws?

    Scott McNaught

      Hello all,

       

      I am running some code which lets me highlight text bits of text found with regular expression.

       

      • The code I have works fine
      • the problem that I am having is that I need to call setTextFormat() over and over again (possibly > 1000 times), and it becomes very slow (possibly because its redrawing over and over).
      • When commenting out the line with setTextFormat(), it runs brilliantly fast.

       

      Is there a way to disable redraws of the textField while I make the changes to the text format, then redraw it manually?

       

      Any help appreciated!

       

      The code is:

       

      // Find the first result
      var pResult:Object = pRegexHighlight.regexp.exec(str);

      while(pResult != null)
      {
          // Highlight the match

          var pTextFormat:TextFormat = new TextFormat();

          pTextFormat.color = 0xff0000;

          textField.setTextFormat(pTextFormat, pResult.index, pResult.index + pResult[0].length);

       

          // Get the next match

          pResult = pRegexHighlight.regexp.exec(str);

      }

       

      Scott McNaught

      http://www.resultswebdesign.com.au/