Search code examples
apache-flexresizescrollhidevisible

Resizing a container when child's visibility is changed?


When I set the visible property to false for a child in a container, how can I get the container to resize? In the example bellow, when clicking on "Toggle", "containerB" is hidden, but the main container's scrollable area is not resized. (I do not want to scroll through a lot of empty space.)

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
    <![CDATA[
        public function toggle():void {
            containerB.visible = !containerB.visible;
        }
    ]]>
</mx:Script>
<mx:VBox height="300" width="200" horizontalAlign="center">
    <mx:Button label="Toggle" click="toggle()" width="200"/>
    <mx:VBox id="containerA" height="400" width="150" horizontalAlign="center">
        <mx:Button label="A" height="400" width="100"/>
    </mx:VBox>
    <mx:VBox id="containerB" height="400" width="150" horizontalAlign="center">
        <mx:Button label="B" height="400" width="100"/>         
    </mx:VBox>
</mx:VBox>


Solution

  • <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            public function toggle():void {
                containerB.visible = !containerB.visible;
            }
        ]]>
    </mx:Script>
    <mx:VBox height="300" width="200" horizontalAlign="center">
        <mx:Button label="Toggle" click="toggle()" width="200"/>
        <mx:VBox id="containerA" height="400" width="150" horizontalAlign="center">
            <mx:Button label="A" height="400" width="100"/>
        </mx:VBox>
        <mx:VBox id="containerB" height="400" width="150" horizontalAlign="center" includeInLayout="{containerB.visible}">
            <mx:Button label="B" height="400" width="100"/>         
        </mx:VBox>
    </mx:VBox>
    </mx:Application>
    

    Hi, just make the containerB includeInLayout property to be dependant on its visible property,

    i just added includeInLayout="{containerB.visible}" in conatinerB property list, this is working, i hope this is wht u were luking for

    have a gr8 time

    Ankur Sharma