views:

347

answers:

1

Hello folks,

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...

A: 

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%5FUS/ActionScript/3.0%5FUsingComponentsAS3/WS5b3ccc516d4fbf351e63e3d118a9c65b32-7f4a.html%5D%5B1%5D

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%5FUS/ActionScript/3.0%5FUsingComponentsAS3/WS5b3ccc516d4fbf351e63e3d118a9c65b32-7f4a.html

Augenfeind