4 Replies Latest reply on Dec 4, 2007 8:38 PM by doug777

    How can I get a container to be the same size as all its children

    doug777 Level 1
      In my TitleWindow, I have two children that size themselves dynamically.

      No problem, TitleWindow also sizes itself to completely show both children.

      Now I have an additional child that I can only position correctly if I set TitleWindow's layout parameter to absolute.

      The third child now positions itself correctly on top of the first child.

      But now TitleWindow is only as big as the first child and I have to scroll to see the second child.

      How can I force TitleWindow to be the size it was when layout was set to vertical?

      Doug
        • 1. Re: How can I get a container to be the same size as all its children
          doug777 Level 1
          I found a way to do this, but it's a bit clunky. If anyone knows a better way would be pleased to hear it.

          This seems to work:

          Put the first two children into a VBox with a creationComplete event.
          In the event handler, set the TitleWindow width and height equal to the VBox width and height, adding to them the widths of the TitleWindow borders.

          Then set TitleWindow.autoLayout = true; and then call validateDisplayList().

          Doug
          • 2. How can I get a container to be the same size as all its children
            deepa subramaniam (adobe) Level 2
            Hi Doug - What exactly are you trying to do? Is the third child being added dynamically, and you want it added above the first child? If so, you can use the addChildAt() method when adding the child to the container. addChildAt() takes an index and the child object is added at that index and all other children are reshuffled to maintain the ordering. IE:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical">
            <mx:TitleWindow layout="vertical" id="tw">
            <mx:Button id="a" />
            <mx:Button id="b" click="go();"/>
            </mx:TitleWindow>
            <mx:Script>
            <![CDATA[
            private function go():void
            {
            var c:Button = new Button();
            c.label="new";
            tw.addChildAt(c, 0);
            }
            ]]>
            </mx:Script>
            </mx:Application>

            Does that help, or am I misinterpreting what you're trying to do?
            • 3. Re: How can I get a container to be the same size as all its children
              doug777 Level 1
              The problem is that the third child has to sit on top of the first child, but in a Panel-type container, the only way I can find to get it to do this is to set TitleWindow.layout = "absolute", otherwise, depending on how you do it, the third child either sits immediately after the second child or (astonishingly) behind the TitleWindow (to discover this I had to change its y position to zero and I could then see it through the semi-transparent TitleWindow border) even though it is definitely the third child.

              Once you set absolute layout, the TitleWindow size becomes the same as the first child only.

              As far as I can see, you have two options with layout in a Panel-type container, either auto (which can be either vertical or horizontal), or absolute. My problem is that I need auto for two of the children and absolute for the other.

              In my solution that does seem to work reliably, I first use it in absolute mode to get the third child positioned correctly, and then in auto mode to get it to size correctly.

              Doug
              • 4. Re: How can I get a container to be the same size as all its children
                doug777 Level 1
                I should add that I can't add the third child until after the first child's creationComplete event fires as I need to know the co-ordinates of the first child in order to place the third child correctly.

                Doug