views:

57

answers:

1

Hi,

Anyone know how to change a single instance of an item renderer for a Flex tree item at runtime? To reiterate, I'm not trying to change the entire tree's item renderer like this:

    tree.itemRenderer = new ClassFactory(ItemRenderer2);

I'm trying to change the item renderer of a single tree item like this (the following code does not work):

    tree.selectedItem.itemRenderer = new ClassFactory(ItemRenderer2);

To put it more simply, does anyone know how to reference an instance of an item renderer and set it to a new item renderer class? I've tried using the Tree's itemToItemRenderer() method with no success.

I'd appreciate any help. Thanks!

Aaron

A: 

I don't know, but on what does the choice of item renderer depend? Data? If so you could make your item renderer a ViewStack that changes depending on the data it receives.

micapam
Thanks for the input micapam! I'm doing something similar already. My item renderer currently has two states: one state renders a label and three button controls, and the other state renders a message, a label, and two button controls. This works great, but I'd like to break up each state into its own item renderer and use each when and where it is needed. To answer your question, the choice of item renderers depends on one of the buttons in the first item renderer. It is a delete item button that switches states to show a confirm delete message with yes and no buttons. =D
Aaron
You might need to extend Tree and override createItemRenderer() - which is defined in its base class, mx.controls.List, on line 1928 (Flex 4.1). I think that's the method that decides which item renderer to use.
micapam