4 Replies Latest reply on Jan 31, 2011 1:36 PM by icanoop

    TreeItemRenderer with variable number of children

    pulse00
      Hi all,

      i'm trying to create a TreeItemRenderer that has a couple of buttons, the number of buttons depends on the data in the item.

      The problem is i don't know where to call the addChild() method on the TreeItemRenderer. Normally i'd override the createChildren() method, however at this stage the data property is not set yet.

      The next thing that came to my mind was the set data() method, unfortunately this method is called several times after the TreeItemRenderer is instantiated, which disqualifies it for adding children i guess.

      Has anyone an idea how this could be accomplished ?

      Any hints greatly appreciated, thanks !
        • 1. Re: TreeItemRenderer with variable number of children
          Level 7

          "pulse00" <webforumsuser@macromedia.com> wrote in message
          news:ghh316$3ru$1@forums.macromedia.com...
          > Hi all,
          >
          > i'm trying to create a TreeItemRenderer that has a couple of buttons, the
          > number of buttons depends on the data in the item.
          >
          > The problem is i don't know where to call the addChild() method on the
          > TreeItemRenderer. Normally i'd override the createChildren() method,
          > however at
          > this stage the data property is not set yet.
          >
          > The next thing that came to my mind was the set data() method,
          > unfortunately
          > this method is called several times after the TreeItemRenderer is
          > instantiated,
          > which disqualifies it for adding children i guess.
          >
          > Has anyone an idea how this could be accomplished ?

          Set a flag in the set data override that says that the data is changed, then
          create or destroy buttons in commitProperties.

          HTH;

          Amy


          • 2. Re: TreeItemRenderer with variable number of children
            pulse00 Level 1
            thanks for the hint. i still have one question about memory usage though:

            Would it be ok to simply create or remove buttons in the commitProperties method and
            the garbage collector would clear the memory of the unused objects when they are
            removed from the itemrenderer ?

            The other thing that came to my mind is to maintain a reference to all DisplayObjects i need
            in the itemrenderer and simply remove / add them to the container as needed.

            I'm a little concerned about memory usage as the Tree that contains those itemrenderers will be
            refreshed quite often.
            • 3. Re: TreeItemRenderer with variable number of children
              Level 7

              "pulse00" <webforumsuser@macromedia.com> wrote in message
              news:ghhesj$ho2$1@forums.macromedia.com...
              > thanks for the hint. i still have one question about memory usage though:
              >
              > Would it be ok to simply create or remove buttons in the commitProperties
              > method and
              > the garbage collector would clear the memory of the unused objects when
              > they
              > are
              > removed from the itemrenderer ?

              They will be garbage collected as long as there are no references to them
              (for instance, no event listeners).

              > The other thing that came to my mind is to maintain a reference to all
              > DisplayObjects i need
              > in the itemrenderer and simply remove / add them to the container as
              > needed.

              You could look at the List Based controls and see how they handle it.

              > I'm a little concerned about memory usage as the Tree that contains those
              > itemrenderers will be
              > refreshed quite often.

              Just make sure not to do anything that can't be garbage collected.