2
votes

When a container component is declared without setting an specific height value, the contaniner's height will be automatically set to a value which makes possible to display all of its content/children without scrolling (when possible).

After the component is initialized with the proper height, I explicitly change the height value of the container.

My question is, after I change the component's height, is it possible to switch back to the original height that was automatically set based on the containers contents? I'm looking for some way to unset the explicit value of the component's height.

3

3 Answers

5
votes

One trick that may be useful for you is to set the height to "NaN", which effectively "unsets" the explicit value you set earlier.

1
votes

Without storing the original height before it was manually changed, I don't believe this is possible.

What you could do is extend whichever base object you're using as a container to add a new property called OriginalHeight (might as well add OriginalWidth while you're there).

Then you would override the set height function to store the original height in your new OriginalHeight property before it gets changed. When you need to set it back, you would just set the container's height = OriginalHeight.

1
votes

contaniner's height will be automatically set to a value

This is not quite automatic. A component will always set the height and width of children; but it can never set the height and width of itself. It can only make suggestions (using the measure method by setting the measuredHeight and measuredWidth property). It is up to the parent container whether it wants to use or ignore those measuredHeight / measuredWidth values.

The Flex Framework containers all have code written for calculating height / width / positioning. IF you are using those, it may seem automatic; but it is actually a fairly manual process. You're just using code someone else wrote.

If you explicitly change the height value of the container, how do you do it? Inside the container (this.height = newvalue ) ? Or does the parent somehow change the height (myContainer.height=newValue)?

Beyond that, it depends what the original height value was. It is possible you can use the measuredHeight value, but I wouldn't count on it. Although, if you are specifying absolute height and absolute width then measure will never be run.

Probably Jason's answer about storing the old value is the best one.