Post Reply 
tree node path
31-03-2008, 04:13 PM (This post was last modified: 31-03-2008 04:21 PM by 34all.)
Post: #1
tree node path
Hello,

this is a really simple one but sometimes the simple ones are the one needed by people around. The following methods returns the path form a tree node to the root node (via parent connection)

Code:
/**
   * Returns an array of all nodes starting from the given node to the tree root node
   * traversing along the successive parent node connection
   * @param n the node to start with
   * @return
   */
        
        private function _getTreeNodePathToRoot(n:NodeSprite):Array {
            
            var path:Array = new Array();
            path.push(n);            
            while (n.parentNode != null) {
                n = n.parentNode;
                path.push(n);
            }
            return path;
            
        }

and the following returns its reverse, the path from the root to the specified node

Code:
/**
   * Returns an array of all nodes starting from the tree root node to the given node
   * traversing along the respective child node connection
   * @param n the node to end up with
   * @return
   */
        
        private function _getTreeNodePathFromRoot(n:NodeSprite):Array {
            return _getTreeNodePathToRoot(n).reverse();
        }

cheers

martin
Find all posts by this user
Quote this message in a reply
12-11-2009, 06:25 AM
Post: #2
RE: tree node path
hi, can you paste here sample of the output? thanks
Find all posts by this user
Quote this message in a reply
12-11-2009, 07:34 AM (This post was last modified: 12-11-2009 04:08 PM by 34all.)
Post: #3
RE: tree node path
Sorry, not really clear to me what you mean. The methods return arrays of NodeSprites of the respective path, nothing more. What kind of output you would like to see?
Find all posts by this user
Quote this message in a reply
Post Reply 


[-]
Quick Reply
Message
Type your reply to this message here.


Image Verification
Image Verification
(case insensitive)
Please enter the text within the image on the left in to the text box below. This process is used to prevent automated posts.

Forum Jump: