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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FlassariCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DeveloperLearningAuthor Commented:
This is perfect. Works very nicely. Thx.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.