Milos Zikic - Personal site, sharing thoughts about startups, products and engineering

Caution when overriding data setter method in Flex

Recently I was presented with a TileList control which was not rearranging properly and seems like it was loosing the items while being resized.
Looking around through the itemrenderer implementation I saw that there is overriden data setter method.

override public function set data(value:Object):void {
if (value != null) {
user= value as User;
}
}



This is wrong!

This was also the cause of all the problems that were there with the TileList not being able to render properly its data. It is very important to call the super.data setter when overriding this method.
This method dispatched Flex Data change event and invalidated display list so it allows component to propertly rerender itself.

The correct override should look like this:


override public function set data(value:Object):void {
super.data = value;
if (value != null) {
user= value as User;
}
}

Share this post