Today I came across a bug where I was using an item renderer in a data grid and the row didn’t highlight when you mouse over it and wouldn’t get selected when you clicked on it (ie, moused over or clicked on the column, not the entire row). The item renderer consisted of 2 Label component.
At first, it was tough to see what the problem could have been. The item renderer is very simple, I have used more complicated item renderers elsewhere that don’t have this problem.
That’s when I noticed that my data setter override didn’t look quite right:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | override public function set data(value:Object):void{ _data = value; if(value){ if(parseInt(value["growth"])>0) this.setStyle("color",LOW_STATE); else if(parseInt(value["growth"])== 0) this.setStyle("color",NORMAL_STATE); if(parseInt(value["growth"])<0) this.setStyle("color",HIGH_STATE); this.text = value["growth"]+"%"; } } |
I was this close to trying to hack in something using the mouseover and mouseclick handlers, when I realized I just needed to do this little change : “super.data = value”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | override public function set data(value:Object):void{ // the missing line that made all the difference super.data = value; _data = value; if(value){ if(parseInt(value["growth"])>0) this.setStyle("color",LOW_STATE); else if(parseInt(value["growth"])== 0) this.setStyle("color",NORMAL_STATE); if(parseInt(value["growth"])<0) this.setStyle("color",HIGH_STATE); this.text = value["growth"]+"%"; } } |
Apparently something in the super class’s data setter does something vitally important, and you really shouldn’t skip that. If you do, BAD stuff will happen.
No related posts.
Tags: itemrendrer, super



