OK, it's a bug.  Here's a class that you can use that fixes the problem.  I 
didn't spend too much time testing it but the basic algorithm worked.  I'll 
file this too.

class FixedTree extends mx.controls.Tree
{
    
        /**
        * Returns the recommended width of the control based on its content. 
You 
        * can calculate this width for all the contents of the control, or 
        * for a subset of items.  This method can be quite time consuming 
because
        * it will measure each of the nodes in the Tree.  The signature of this 
method is<br> 
        * <pre>calculateWidth(count)</pre><br>
        * <i>count</i> - Number of items to measure. This parameter is optional.
        * @param count Number of nodes to measure.
        */
        function calculateWidths(count)
        {
            if (count==undefined) count = 10000; // a hard limit on number of 
nodes to measure.
            var children = treeDataProvider.getChildNodes();
            var idx = 0;
            var len = children.length;
            var curNode;
            var hiddenRow = 
listContent.createClassObjectWithStyles(__rowRenderer, "testRow", hiddenRowZ, 
{_visible:false, owner:this, styleName:this, rowIndex:0});
            hiddenRow.setSize(layoutWidth, hiddenRow.preferredHeight);
            var maxW = 0;
            var done=false;
            var dStack = new Array();
            var curCount = 0;
            while (!done) {
                curCount++;
                curNode = children[idx];
                if (curCount>count) break;
                hiddenRow.setValue(curNode, "normal");
                hiddenRow.setState("normal", false);
    //          trace("measuring " + curNode.getProperty("label")+ " " + 
hiddenRow.cell._x + " " + hiddenRow.cell.getPreferredWidth());
                maxW = Math.max(hiddenRow.calculateWidth(), maxW);
                if (curNode.getChildNodes().length>0) {
                    //node has kids
                    if (idx+1 < len) {
                        dStack.push({children: children,idx: idx+1,len: len});
                    }
                    children = curNode.getChildNodes();
                    len = children.length;
                    idx = 0;
                } else {
                    if (idx+1 < len) {
                        idx++;
                    } else if (dStack.length>0) {
                        var parentData = dStack.pop();
                        children = parentData.children;
                        len = parentData.len;
                        idx = parentData.idx;
                    } else {
                        done = true;
                    }
                }
    
            }
            var o = getViewMetrics();
    //      trace(maxW + o.left + o.right);
    
            listContent.destroyObject("testRow");
    
            return maxW + o.left + o.right;
    
        }

    
}

________________________________________
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of pilby1
Sent: Tuesday, May 24, 2005 12:30 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Tree component's calculateWidth() method, does it 
work?

No, that's not the problem. I did notice how I had the missing 's' 
after the fact, but in my code, it is calculateWidths(). If you would 
just create a tree component and try it, you will see calculateWidths
() always returns NaN.

--- In flexcoders@yahoogroups.com, Manish Jethani 
<[EMAIL PROTECTED]> wrote:
> On 5/23/05, pilby1 <[EMAIL PROTECTED]> wrote:
> 
> > Checking the documentation, it seems like the method, 
calculateWidth
> > (), is my answer. However, doing tree.calculateWidth() always 
returns
> > NaN, making it useless.
> 
> It's 'calculateWidths' (with an 's').  Could that be the problem?



________________________________________
Yahoo! Groups Links
* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
  
* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
  
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to