You cannot just drop in any renderer for a Tree component or Menu which need to deal with indentation because your renderer doesn’t know anything about it. Instead, the easiest thing to do is to use an itemRenderer that subclasses the TreeItemRenderer class. Here is an example of a Tree item renderer. The renderer will change the font weight and color of parent nodes and add text as to how many children each node has.

 

 

package

{

 

import mx.controls.treeClasses.*;

import mx.collections.*;

 

            public class MyTreeItemRenderer extends TreeItemRenderer

            {

                       

                public function MyTreeItemRenderer()

                {

                         super();

                         mouseEnabled = false;

                                   

                }

                       

                override public function set data(value:Object):void

                {

                         super.data = "">

                         if(TreeListData(super.listData).hasChildren)

                         {

                             setStyle("color", 0xff0000);

                             setStyle("fontWeight", 'bold');

                        }

                        else

                        {

                             setStyle("color", 0x000000);

                             setStyle("fontWeight", 'normal');

                        }

                }

             

               override protected function updateDisplayList(unscaledWidth:Number,  unscaledHeight:Number):void

               {

                        super.updateDisplayList(unscaledWidth, unscaledHeight);

                        if(super.data)

                        {

                              if(TreeListData(super.listData).hasChildren)

                              {

                                     var tmp:XMLList = new XMLList(TreeListData(super.listData).node);

                                     var myStr:int = tmp[0].children().length();

                                     super.label.text =  TreeListData(super.listData).text + "(" + myStr + ")";

                             }

                       }

              }

      }

}


From: [email protected] [mailto:[email protected]] On Behalf Of pasflex
Sent: Wednesday, March 22, 2006 9:52 AM
To: [email protected]
Subject: [flexcoders] Tree itemRenderer - flex 2

 

When setting an itemRenderer for a tree in flex2, the tree controls
and indentation disappear.  For example, if I try to display a label
and an image for each node in the tree and I create an itemrenderer to
do so, the tree will only display the root node using the itemrenderer
with no controls to open it (basically turning the tree into a one
item list).
In flex 1.5 a cellrenderer assigned to a tree didn't override the
default tree behavior, it only changed the renderering of the item in
the node.
How does one accomplish this is flex2?

Thanks






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to