6 Replies Latest reply on Dec 9, 2008 8:16 PM by nickname118

    how to calculate the height of a dynamic container

    nickname118 Level 1
      Hi, I am trying to figure out a way to calculate the height of a container after a child is added, but before the application has finished loading. Is this possible? I wanted to add data to certain objects until they reach a certain height, and then start adding them to the next.

      I understand that in flex DisplayObjects, or whatever, are not fully initialized until all of their children have initialized and fired their creationComplete events. Can this behavior be overriden? I tried to changed the creationPolicy on all my containers to "ALL", but this did nothing. All of the height variables of my container (height, measuredHeight,explicitHeight) are all 0 or NaN still. (Although, I should say that the measuredHeight variable on rare occasion will display the correct height in the debugger.)

        • 1. Re: how to calculate the height of a dynamic container
          Level 7

          "nickname118" <webforumsuser@macromedia.com> wrote in message
          news:ghk31l$sue$1@forums.macromedia.com...
          > Hi, I am trying to figure out a way to calculate the height of a container
          > after a child is added, but before the application has finished loading.
          > Is
          > this possible? I wanted to add data to certain objects until they reach a
          > certain height, and then start adding them to the next.

          child1.getExplicitOrMeasuredHeight() + child2.getExplicitorMeasuredHeight...


          • 2. how to calculate the height of a dynamic container
            nickname118 Level 1
            Thank you for your help in this.

            I think that method is working. However I have another problem now.
            It seems that When I add components to a container within a TabNavigator, the TabNavigator is not updating the height. How can I go about forcing the TabNavigator to update its size?

            For example. Let's say that I've added some stuff to a container. Then I let the program run and let everything draw. Then later on an event is fired and I add stuff to the container again. The container grows in height. Yet the TabNavigator wrapping the container does not change its size, causing the view of components inside to be cut off.
            • 3. Re: how to calculate the height of a dynamic container
              Level 7

              "nickname118" <webforumsuser@macromedia.com> wrote in message
              news:ghm6tc$lvc$1@forums.macromedia.com...
              > Thank you for your help in this.
              >
              > I think that method is working. However I have another problem now.
              > The container I am using happens to be a VBox inside of a Tab Navigator.
              > When I add components to this after the creation_complete event is called
              > by
              > the VBox, there are not appearing on the screen. That is to say when I add
              > some
              > stuff to the VBox, then let the program run. Then later when the
              > creation_complete or update_complete is fired I try to add more things to
              > the
              > VBox. I have tested adding components, in this event handler, to every
              > other
              > container in my app both inside and outside the tab navigator and they do
              > in
              > fact appear on the screen. However, they do not show up when I add to the
              > VBox,
              > which is what I wanted to use to lay things out.
              >
              > Is there something special I can do force VBox to draw the newly added
              > components at runtime?
              >
              > The hierarchy of my app is something like this
              >
              > <Application>
              > <VBox>
              > /* buttons and menu stuff */
              > <TabNavigator>
              > <VBox/>
              > <VBox/>
              > ...etc
              > </TabNavigator>
              > </VBox>
              > </Application>

              Have you considered adding them in the addChildren method instead?

              What code are you using?


              • 4. Re: how to calculate the height of a dynamic container
                nickname118 Level 1
                No, I don't have any addChildren() method. I just call addChild().

                I've done some work, and I've figured out that items are added, however the parent container does not adjust its size. Is there some sort of event I need to fire to make the outside containers adjust their size when I change stuff?

                say I add some label to the Vbox inside my TabNavigator.
                Then I wait for update_complete.
                I read the height and it is 30 or something.
                Then I add more components to the VBox.
                Then I wait for another update_complete.
                the height is still the same height as the first item I put in it, 30.

                The display shows just the first label, however if I turn on a verticalScrollPolicy for the VBox, then I can scroll down to see that there is indeed more content, but the container never resized itself.

                So the height is updating when I add the first item, which is before the application completes. Then after that any time I add an item the height is not affected. What events get fired before that don't happen after the application renders itself?
                • 5. Re: how to calculate the height of a dynamic container
                  Level 7

                  "nickname118" <webforumsuser@macromedia.com> wrote in message
                  news:ghmm90$bs4$1@forums.macromedia.com...
                  > No, I don't have any addChildren() method. I just call addChild().

                  My mistake. I meant the createChildren() method that all components have.

                  > I've done some work, and I've figured out that items are added, however
                  > the
                  > parent container does not adjust its size. Is there some sort of event I
                  > need
                  > to fire to make the outside containers adjust their size when I change
                  > stuff?

                  Have you tried simply calling invalidateSize()?

                  > say I add some label to the Vbox inside my TabNavigator.
                  > Then I wait for update_complete.
                  > I read the height and it is 30 or something.
                  > Then I add more components to the VBox.
                  > Then I wait for another update_complete.
                  > the height is still the same height as the first item I put in it, 30.
                  >
                  > The display shows just the first label, however if I turn on a
                  > verticalScrollPolicy for the VBox, then I can scroll down to see that
                  > there is
                  > indeed more content, but the container never resized itself.

                  Yes, I'm thinking it's depending on you to call invalidateSize(), though I'm
                  a bit surprised addChild doesn't do this under the hood.

                  > So the height is updating when I add the first item, which is before the
                  > application completes.

                  Probably happens before measure().

                  > Then after that any time I add an item the height is not
                  > affected. What events get fired before that don't happen after the
                  > application
                  > renders itself?

                  I'm thinking if you want commitProperties(), updateDisplayList, and
                  measure() to fire again, you'll have to call the appropriate invalidation
                  methods yourself, though I'm surprised addChild doesn't do that for you.

                  HTH;

                  Amy


                  • 6. Re: how to calculate the height of a dynamic container
                    nickname118 Level 1
                    Ah, thanks again for your help.

                    I will figure out tomorrow which invalidate method to try.