4 Replies Latest reply on Feb 12, 2007 7:48 PM by doug777

    Expand Tree Control

    doug777 Level 1
      I now have a Tree Control populated from an ArrayCollection and using the defaultDataDescriptor.

      At this point in the program the data exists only in the myTree.dataProvider and the root node is at myTree.dataProvider[0] or myTree.dataProvider.source[0] and I can see from the variables window that the correct data is located here.

      What do I have to put for 'item' in myTree.expandChildrenOf(??item??, true). Everything I can think of returns:

      "Cannot access a property or method of a null object reference."

      Does anyone have any idea how to make this work.

      Doug
        • 1. Re: Expand Tree Control
          _Albertx_ Level 1
          Well.

          In fact, "item" must be an object in your tree, for example, myTree.selectedItem, or dataProvider[0]. But if you get errors just try this...

          Don't call expandChildrenOf immediately after you set the dataProvider for the tree component, and put your statement "expandChildrenOf" inside a try / catch block. This will prevent for getting errors if there aren't.
          • 2. Re: Expand Tree Control
            doug777 Level 1
            The error occurs in the Flex file Tree.as at line 1383.

            I can now see that the null object is not item - dataProvider[0], this contains the correct data. The problem is that iterator is null and therefore iterator.view is a null reference.

            Is there any way to solve this problem?

            My ArrayCollection is built in pretty much the same way as shown in:

            Flex 2 Developer's Guide > Building User Interfaces for
            Flex Applications > Using Data Providers and Collections > Using hierarchical data providers > Data descriptors and hierarchical data provider structure > Creating a custom data descriptor

            But I have used the defaultDataDescriptor and my arrays are not built from literals.

            Doug
            • 3. Re: Expand Tree Control
              doug777 Level 1
              I have tried calling myTree.validateNow() immediately before expandChildren, but it still fails in Tree.as with iterator = null, although iteratorValid = true.

              Doug
              • 4. Re: Expand Tree Control
                doug777 Level 1
                Okay solved the problem.

                To make expandChildren work, you have to do things in this order. First create the Tree and set any Properties you need. Then you must add the Tree to its container, then call validateNow() and then finally you can call expandChildren.

                Thanks very much for you help. Until you replied I was stuck on the thought that it had to be item that was wrong.

                Doug