views:

235

answers:

1

I have item renderers in an mx.controls.Tree that I need to refresh on demand.

I have code in the updateDisplayList that fires for only some of the visible nodes no matter what I do. I've tried triggering a change that they should all be listening for; I have tried clearing and resetting the dataProvider and the itemRenderer properties.

        private function forceCategoryTreeRefresh(event : Event = null) : void
        {
            trace("forceCategoryTreeRefresh");

            var prevDataProvider : Object = CategoryTree.dataProvider;
            CategoryTree.dataProvider = null;
            CategoryTree.validateNow();
            CategoryTree.dataProvider = prevDataProvider;

            var prevItemRenderer : IFactory = CategoryTree.itemRenderer;
            CategoryTree.itemRenderer = null;

            CategoryTree.itemRenderer = prevItemRenderer as IFactory;

            _categoriesChangeDispatcher.dispatchEvent(new Event(Event.CHANGE));
        }

The nodes refresh properly when I scroll them into view (e.g. the .data gets set), but I cannot force the ones that already exist to refresh or reset themselves.

Any ideas?

A: 

ItemRenderers in Flex are virtualized so there will not always be one ItemRenderer for each Tree node.

However, you can invalidate the nodes to force a refresh. The answer to this question gives an example of how to do that.

Jason W