Gordon,

I agree with you completely that the drawing code should be in the
updateDisplayList() and this is exactly what I had done in the
previous iterations.  While testing the tree today, I noticed from the
debugger that the drawing code was being repeatedly fired and the tree
slowed down to a crawl. So after a few tests, I decided to put the
drawing code in the property and it seeemed to have solved the
problem.  The tree became much more responsive and the lines were
still being redrawn correctly.   You can try it.  Perhaps I stumbled
into a bug. 

Thanks,

Tim


--- In flexcoders@yahoogroups.com, "Gordon Smith" <[EMAIL PROTECTED]> wrote:
>
> Drawing code doesn't belong in property setters; it belongs in
> updateDisplayList(). For example, if something causes the row height to
> change, the data setter won't get called and the lines won't redraw.
>
> Are you saying that updateDisplayList() is getting called more
> frequently than it should be?
>
> - Gordon
>
>
> -----Original Message-----
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of sufibaba
> Sent: Friday, May 26, 2006 2:58 PM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Bet3 Tree with Lines -- 3rd cut.
>
> Hello All,
>
> A new update to the MyTreeItemRenderer.as
> Changes:  moved drawing logic out of updateDisplayList() and into the
> set data() block.  This stop the lines from being drawn again and
> again which means that the tree is much more repsonsive.
>
>
> ---------- MyTreeItemRenderer.as ------------
>
> package {
>
>     import mx.controls.treeClasses.*;
>     import mx.collections.*
>     import flash.display.Sprite;
>   
>
>     public class MyTreeItemRenderer extends TreeItemRenderer {
>
>       private var isLast:Boolean;
>       private var lineColor:uint = 0x666666;
>       private var lineWidth:Number = .5;
>      
>      
>       private var lineArr:Array =new Array();
>         // Define the constructor.
>         public function MyTreeItemRenderer() {
>             super();
>         }
>        
>         // Override the set method for the data property
>         // to set the font color and style of each node.
>         override public function set data(value:Object):void {
>              
>             super.data = ""> >            
>             if (TreeListData(super.listData)){
>                   if(TreeListData(super.listData).hasChildren) {
>                       setStyle("color", 0xff0000);
>                       setStyle("fontWeight", 'bold');
>                   }
>                   else {
>                       setStyle("color", 0x000000);
>                       setStyle("fontWeight", 'normal');
>                   } 
>
>                        
>                         // graphics.clear(), needed to clean up
> previously drawn
> lines, otherwise it extra lines will be drawn
>                         graphics.clear();
>                        
>                         ///////////////////////////////
>                         // Line drawing Logic
>                        
>                               var node:Object =
> TreeListData(super.listData).item;
>                               var depth:Number =
> TreeListData(super.listData).depth;
>                               var indent:Number =
> TreeListData(super.listData).indent ;
>                              
>                               lineArr =new Array();
>                              
>                               // FolderNode
>                       if(TreeListData(super.listData).hasChildren) {
>                           var tmp:XMLList = new
> XMLList(TreeListData(super.listData).item);
>                           var myStr:int = tmp[0].children().length();
>                           super.label.text =
> TreeListData(super.listData).text + "(" + myStr + ")";
>                           graphics.lineStyle(.7,
> lineColor,.3,false,"NONE");
>      
>                                     trace("depth = " +
> TreeListData(super.listData).depth + ", open
> = " + TreeListData(super.listData).open + ", rowIndex = " +
> TreeListData(super.listData).rowIndex);
>                                    
>                                     //trace("icon = " +
> TreeListData(super.listData).icon );
>                                    
>                                     // makeLastChildArr
> calls grandparentnode in order to determine
> whether the parent's
>                                     // node is the last
> child.
>                                     // if no grandparent
> node exist, then it will give an error.
>                                     if ( depth > 2){
>      
> makeLastChildArr(node,depth,depth);
>                                           if (depth >3){
>      
> makeLastChildArr(node,3,depth);
>                                           }
>                                          
>      
> //trace("isLastChild = " + isLast + " i=" + i);
>      
> trace("lineArrLen = " + lineArr.length );
>                  
>                                           lineArr =
> lineArr.reverse();
>                                           for (var
> i:Number=0;i< lineArr.length;i++){
>      
> trace("lineArr = " + lineArr[i] + " i=" + i);
>                                                
>                                           }
>                                    
>                                           for(var
> i:Number=1;i<=depth;i++){
>                                                
>                                                 var
> parentDropLine:Boolean = false;
>                                                
>      
> TreeListData(super.listData);
>            
>                                                 if(i ==
> depth ){
>      
> drawChildFolderLines(indent);
>                                                 }
>                                                 else {
> // Preceding lines
>      
> if (i != 1 ){ // don't draw first line
>      
> // pull out from correct index of lineArray
>      
> isLast = lineArr[i-2];
>      
> // draw line if corresponding parent is not lastchild
>      
> if (!isLast){
>      
> drawParentLines(i);
>      
> }//if
>      
> }//if
>                                                 }//else
>                                           }//for
>                                     }// > 2
>                                    
>                                     else if ( depth == 2){
>                                           var
> offset:Number = 23;
>      
> graphics.moveTo(offset,-8);
>      
> graphics.lineTo(offset,2);
>                                          
>                                     }
>                       }
>                       // LeafNode
>                       else{
>      
>      
> makeLastChildArr(node,3,depth);
>                                     //trace("isLastChild = "
> + isLast + " i=" + i);
>                                     trace("lineArrLen = " +
> lineArr.length );
>            
>                                     lineArr =
> lineArr.reverse();
>                                     for (var i:Number=0;i<
> lineArr.length;i++){
>                                           trace("lineArr =
> " + lineArr[i] + " i=" + i);
>                                          
>                                     }
>      
>                                     for(var
> i:Number=1;i<=depth;i++){
>                                          
>                                           var
> parentDropLine:Boolean = false;
>                                    
>                                           if(i == depth ){
>
>      
> drawChildLeafLines(indent);
>                                           }
>                                           else { //
> Preceding lines
>                                                 if (i !=
> 1 ){ // don't draw first line
>                                                 // pull
> out from correct index of lineArray
>      
> isLast = lineArr[i-2];
>      
> // draw line if corresponding parent is not lastchild
>      
> if (!isLast){
>      
> drawParentLines(i);
>      
> }//if
>      
>      
>      
>
>                                                 }//if
>                                           }//else
>                                     }//for
>                                    
>                       }
>                  
>             } // super.data
>            
>         }
>
>       
>           public function makeLastChildArr(node:Object,
> requestedLevel:Number, startLevel:Number):Boolean {
>                
>                       trace("isLastChild = " + node.toXMLString() + "
> requestedLevel = " + requestedLevel + " startLevel = " + startLevel);
>                         var isLastFlag:Boolean = false;
>
>                         var parentNode:XML = node.parent();
>                         var grandParNode:XML =
> parentNode.parent();
>                        
>                         if (grandParNode){
>                               var children:XMLList =
> grandParNode.children();
>                               var noOfChildren:Number =
> children.length();
>      
>                               //trace("parentNode = " +
> parentNode.toXMLString() + "
> grandParNode = " + grandParNode.toXMLString() + " noOfChildren = " +
> noOfChildren);
>                               //trace("foundNode = " +
> children[noOfChildren -1] + ", Node = "
> + node.toXMLString() );
>                               if ( parentNode ==
> children[noOfChildren -1]){
>                                     //trace("foundNode = " +
> children[noOfChildren -1] + ", Node = "
> + node.toXMLString );
>                                     isLastFlag = true;
>                               }
>
>                               lineArr.push(isLastFlag);
>                              
>                               if (requestedLevel !=
> startLevel){
>      
> makeLastChildArr(node.parent(), requestedLevel, startLevel - 1);
>                               }
>                         }
>                        
>                         return isLastFlag;
>             }
>
>         public function drawParentLines(i:Number):void {
>                   graphics.lineStyle(lineWidth,
> lineColor,.3,false,"NONE");
>                   var offset:Number = i*17 - 11;
>                   if (i == 2){offset = 23};
>                   graphics.moveTo(offset,-8);
>                   graphics.lineTo(offset,14);
>             }
>            
>         public function drawChildLeafLines(indent:Number):void {
>                   graphics.lineStyle(lineWidth,
> lineColor,.3,false,"NONE");
>                   var offset:Number = indent + 6.5;
>
>                   graphics.moveTo(offset,-8)
>                   graphics.lineTo(offset,10);
>                   graphics.moveTo(offset,10);
>                   graphics.lineTo(offset + 10,10);
>                  
>                  
>             }
>
>         public function drawChildFolderLines(indent:Number):void {
>                   graphics.lineStyle(lineWidth,
> lineColor,.3,false,"NONE");
>                   var offset:Number = indent + 6.5;
>                   graphics.moveTo(offset,-8);
>                   graphics.lineTo(offset,2);
>             }
>
>
>
>         // Override the updateDisplayList() method
>         // to set the text for each tree node.       
>        override protected function
> updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
>             super.updateDisplayList(unscaledWidth, unscaledHeight);
>             if(super.data) {
>                  
>          
>                              
>             }// super data
>            
>           }
>       }
> }
>
>
> ----------End: MyTreeItemRenderer.as ------------
>
> Cheers,
>
> Tim
>
>
>
>
>
>
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives:
> http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>







--
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