title: Flex 4 dynamically resize parent container to contain children
body: <p>Is there an easy way to make a parent container (eg Group) resize when it's children resize?</p>
  
  <p>Below is a little example app. When I put the 200x200 'food' in the 'stomach' the stomach &amp; it's containing 100x100 'body' should resize to contain the food.</p>
  
  <p>Any ideas?</p>
  
  <p>(from this gist <a href="http://gist.github.com/301292" rel="nofollow noreferrer">http://gist.github.com/301292</a>)</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo"
        minWidth="1024"
        minHeight="768"
        creationComplete="application1_creationCompleteHandler(event)"&gt;
   &lt;fx:Script&gt;
    &lt;![CDATA[
     import mx.events.FlexEvent;
  
     protected function application1_creationCompleteHandler(event:FlexEvent):void {
  
     }
  
     protected function eatFoodTrigger_clickHandler(event:MouseEvent):void {
      var food:Border = new Border();
      food.setStyle('backgroundColor', 0x15DCA9);
      food.width = 200;
      food.height = 200;
  
      stomach.addElement(food);
  
     }
    ]]&gt;
   &lt;/fx:Script&gt;
  
   &lt;s:Group verticalCenter="0" horizontalCenter="0"&gt;
    &lt;s:layout&gt;
     &lt;s:VerticalLayout horizontalAlign="center" /&gt;
    &lt;/s:layout&gt;
  
    &lt;s:Label fontSize="24" text="The 100x100 pink/brown body has a stomach inside it.
       Press eat and the stomach gets 200x200 'food' added to it.
       I want the body and the stomach to expand to fit the food." width="200"&gt;
    &lt;/s:Label&gt;
  
    &lt;s:Border id="body"
        backgroundColor="0x333333"
        minWidth="100"
        minHeight="100"
        borderColor="0xFF4466"
        borderWeight="5"&gt;
     &lt;s:Group id="stomach"&gt;
     &lt;/s:Group&gt;
    &lt;/s:Border&gt;
  
    &lt;s:Button id="eatFoodTrigger" click="eatFoodTrigger_clickHandler(event)" label="eat" /&gt;
   &lt;/s:Group&gt;
  &lt;/s:Application&gt;
  </code></pre>