views:

267

answers:

3

Question for Flex guys. How can I use multiple item renderers in mx:Tree depending on item's depth/level in tree? For example. For the first level items I want to use label with button and for second level items combobox.

Is this somehow possible?

A: 

That conditional logic should be implemented in a single itemrenderer. You can't set multiple renderers.

Here is a receipe how this can be implemented: http://cookbooks.adobe.com/post_How_do_I_create_a_Tree_itemRenderer_-62.html

override public function set data(value:Object):void
        {
            if(value != null)
            { 
                super.data = value;
                if(TreeListData(super.listData).hasChildren)
                {
                    setStyle("color", 0x660099);
                    setStyle("fontWeight", 'bold');
        }
        else
        {
            setStyle("color", 0x000000);
            setStyle("fontWeight", 'normal');
        }
            }
         }  

That 'if' statement shows you if you have inner nodes or not. You also can specify additional property when generating the data provider.

mico
Thanks, I implemented main itemRenderer with 2 extended classes and do switching in overriden function set data. But how I determine node depth?
luccio
just run in some issues...I'm trying to do it this way in set data():if (depth == 1) { itemRenderer = itemRendererOne;} else { itemRenderer = itemRendererTwo;}But it changes itemRenderer in whole tree. Is it somehow possible to switch it only for specific item?
luccio
A: 

Here is solution: In extended Tree just override function getItemRendererFactory(data:Object):IFactory and do neccessary logic to select proper itemRenderer.

Hope this will help also someone else

luccio
A: 

Hello, can some1 help me to get the node depth from a tree.

ron