I just ran into a bug in my app as follows: ListView has the following function: protected function rollOverIndexChangeHandler(event:Event):void { if (lastRollOverIndex != -1) { var ir:ISelectableItemRenderer = dataGroup.getItemRendererForIndex(lastRollOverIndex) as ISelectableItemRenderer; ir.hovered = false; } if (IRollOverModel(listModel).rollOverIndex != -1) { ir = dataGroup.getItemRendererForIndex(IRollOverModel(listModel).rollOverIndex) as ISelectableItemRenderer; ir.hovered = true; } lastRollOverIndex = IRollOverModel(listModel).rollOverIndex; }
I have code which changes the contents of my dataGroup. When the contents change, the number of elements in the dataGroup can increase or decrease. The ListView keeps track of the last hovered (and selected) index and tries to clear the hovered/selected property on that. When the dataGroup changes, the old index can become invalid and throw an RTE when trying to access an index that’s out of range in the dataGroup. The easiest way to fix this is to change: if (lastRollOverIndex != -1) to: if (lastRollOverIndex != -1 && lastRollOverIndex < dataGroup.numElements) Of course, this is just-in-case code so I’d like to avoid this if possible. Additionally, it does not clear out the old hovered/selected properties when the dataGroup is swapped out. Any other suggestions on how to solve this problem? Harbs