1 Reply Latest reply on Jun 6, 2010 1:45 AM by David_F57

    Autoadjust height of a s:Group

    MageshR Level 1

      Hi - I need to auto adjust height of a S:Group depending on the content of the group. The contents would be added dynamically via script using group.addElement Pls let me know how can this be accomplished. Any sample code would be appreciated.

        • 1. Re: Autoadjust height of a s:Group
          David_F57 Level 5

          hi,

           

          A group will automatically adjust its dimensions to fill content as long as you dont specify width or height. With the code below you will notice that the height of the group changes as you add a component, the width changes when the component width exceeds the group width, just keep adding components to see the effect.

           

          David

           

          <?xml version="1.0" encoding="utf-8"?>

          <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/mx" minWidth="955" minHeight="600">

           

          <fx:Script>

          <![CDATA[

           

          private var ypos:int=10;

           

          protected function button1_clickHandler(event:MouseEvent):void

          {

          var btn:Button = new Button();

          btn.x=10;

          btn.y=ypos;

          btn.label="hello at "+String(ypos);

          ypos +=40;

          grp.addElement(btn);

          }

           

          ]]>

          </fx:Script>

          <s:Group id="grp" top="10" left="140">

          <s:Rect top="0" left="0" bottom="0" right="0">

          <s:stroke>

          <s:SolidColorStroke weight="2" color="0xCCFFCC"/>

          </s:stroke>

          </s:Rect>

          </s:Group>

          <s:Button x="46" y="10" label="Add A button" click="button1_clickHandler(event)"/>

          </s:Application>