4 Replies Latest reply on Sep 17, 2008 9:23 AM by EvolvedDSM

    auto height of a component

    ilsh Level 1
      I have a simple "Label" component. I want to set its height either to 0, or it's native height depending on a condition. Right now I have
      <mx:Label text="test" height="{condition?0:20}" />
      How can I change 20 in the code to something which is the label's native height?
        • 1. Re: auto height of a component
          webvalue Level 1
          Is native height the same as the default height? Is so, I would use a bindable variable and store the default height to it, and then place the name of the variable into your expression:

          [Bindable]
          myLabelHeight:int;
          private function creationComplete():void {
          myLabelHeight = thelabel.height;
          }

          <mx:Label text="test" height="{condition?0:myLabelHeight }" />
          • 2. Re: auto height of a component
            ilsh Level 1
            thanks, webvalue. Is there a simpler way? e.g, something like:

            <mx:Label text="test" height="{condition?0:'auto'}" />

            (I have so many components to be hidden depending on the condition and it's a pain to get the height of all of them).
            • 3. Re: auto height of a component
              webvalue Level 1
              How about put some code in AS block to loop through an array of all labels ids?
              • 4. auto height of a component
                EvolvedDSM Level 2
                Are you setting the height to zero just to hide your Label? You could use some flag conditionals with the visible attribute. Give your Label an id, like so:
                <mx:Label id="label1" text="test"/>

                Then, code some functions that toggle the visible attribute:
                private function showLabel():void{
                label1.visible = true;
                }

                private function hideLabel():void{
                label1.visible=false;
                }

                or, you could do if-statement conditionals depending on what triggers your label to show or hide