Search code examples
flashactionscript-3actionscript

DataGrid-CellRenderer: Multiple colors for text


can someone tell me how I can manage to give single words inside a DataGrid-CellRenderer a different color than defined by the TextFormat for that CellRenderer? It's not how to get these single words, it's how to use more than one color inside one cell...


Solution

  • I've received the solution in the Flashcoders mailing list yesterday and it really hist the spot:

    I adapted the example on the following page to show you a quick test:

    [http://help.adobe.com/en_US/ActionScript/3.0_UsingComponentsAS3/WS5b3ccc516d4fbf351e63e3d118a9c65b32-7f4a.html][1]

    I changed the drawLayout function to highlight the word "renderer" in red. You need to import TextFormat and TextField classes too.

    override protected function drawLayout():void {
      textField.width = this.width;
      var text:String = textField.text;
      var tf:TextFormat = textField.getTextFormat();
      var redIdx:int = text.indexOf("renderer");
      if (-1 != redIdx) {
        tf.color = 0xff0000;
      }
      TextField(textField).setTextFormat(tf, redIdx, (redIdx + 8));
      super.drawLayout();
    }
    

    [1]: http://help.adobe.com/en_US/ActionScript/3.0_UsingComponentsAS3/WS5b3ccc516d4fbf351e63e3d118a9c65b32-7f4a.html