Update: See comment#1 by Justin Mclean.
WindowShades resize to their content, even if you change the content dynamically. But it only does this until the first time you close and reopen the WindowShade. The reason is that it uses an effect to close itself. And by using this effect, it sets the ‘height’ property. And because of that, the component does not automatically resize depending on its content.
You can solve this by extending the WindowShade. First you have to override ‘runResizeEffect’. The main thing is to put an event listener to the effect end event.
private var _resize:Resize;
override protected function runResizeEffect():void {
if (_resizeĀ AND _resize.isPlaying) {
_resize.end();
}
_resize = new Resize(this);
_resize.addEventListener(EffectEvent.EFFECT_END, handleEffectEnd, false, 0, true);
_resize.heightTo = Math.min(maxHeight, measuredHeight);
_resize.duration = RESIZE_DURATION;
_resize.play();
}
Then in the effect end handler, set the height to NaN so the WindowShade can resize automatically again.
private function handleEffectEnd(event:EffectEvent):void {
// We set height = NaN so that the component resizes automatically
// to the height of its children.
height = NaN;
}
#1 by Justin Mclean - February 9th, 2010 at 05:40
Thanks a great help. BTW there’s an easier way of doing this without overriding the runResizeEffect method as the resize event will bubble. I’ve written it up here:
http://blog.classsoftware.com/index.cfm/2010/2/9/How-to-fix-FlexLib-WindowShade-resize-issues
#2 by admin - February 9th, 2010 at 07:45
Thanks Justin! I didn’t check you method but by looking at it, it should work.