Advanced DataGrid Red/Blue Color Renderer

I am trying to get colors red/blue for the numbering in advanceddatagrid columns. I received solution from Experts-Exchange but it does not seem to work at the line  "super.data = value" shown below.

I had to post this question again because I accepted the solution to my original question and now I cannot request it again. Sorry.

The original question is posted under the Title 'Flex : ItemRenderer For blue/red font number color in advanceddatagrid causing grid to slow '  if anyone wants to search for the history.  

I get following error

 if (value[DataGridListData(listData).dataField] < 0)

as

TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at ascripts::ColorRenderer/set data()[\src\RedBlueColorRenderer.as:12]
      at mx.controls::AdvancedDataGridBaseEx/http://www.adobe.com/2006/flex/mx/internal::setupRendererFromData()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\AdvancedDataGridBaseEx.as:2047]
      at mx.controls::AdvancedDataGridBaseEx/measureItems()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\AdvancedDataGridBaseEx.as:7058]
      at mx.controls::AdvancedDataGridBaseEx/commitProperties()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\AdvancedDataGridBaseEx.as:1993]
      at mx.controls::AdvancedDataGrid/commitProperties()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\AdvancedDataGrid.as:2276]
      at mx.core::UIComponent/validateProperties()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:5807]
      at mx.managers::LayoutManager/validateProperties()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:539]
      at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:659]
      at Function/http://adobe.com/AS3/2006/builtin::apply()
      at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628]
      at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]

package
{
        import mx.controls.Label;
        import mx.controls.dataGridClasses.DataGridListData;

        public class RedBlueColorRenderer extends Label
        {
                public override function set data(value:Object) : void {
                        super.data = value;
                        
                        if (value[DataGridListData(listData).dataField] < 0)
                                setStyle("color", "red");
                        else
                                setStyle("color", "blue");                                      
                }               
        }
}

Open in new window

DeveloperLearningAsked:
Who is Participating?
 
FlassariConnect With a Mentor Commented:
The flex framework might be setting data as null, add a null check to your code and see if that helps.

package
{
        import mx.controls.Label;
        import mx.controls.dataGridClasses.DataGridListData;

        public class RedBlueColorRenderer extends Label
        {
                public override function set data(value:Object) : void {
                        super.data = value;
                        if (!value) return;
                        
                        if (value[DataGridListData(listData).dataField] < 0)
                                setStyle("color", "red");
                        else
                                setStyle("color", "blue");                                      
                }               
        }
}

Open in new window

0
 
DeveloperLearningAuthor Commented:
This is perfect. Works very nicely. Thx.
0
All Courses

From novice to tech pro — start learning today.