I'd love to wrap up this task. Does anyone have any other suggestions?

On Tue, May 27, 2008 at 8:24 PM, Richard Rodseth <[EMAIL PROTECTED]> wrote:
> I'm afraid I'm still struggling with this. The classes below work
> (more or less) if I supply a large button as "content", but if I try a
> VBox it appears to shrink to nothing. Any ideas? Hopefully the
> formatting survived.
>
>                <view:ScaleOrCenterView width="100%" height="100%"   >
>                        <mx:VBox borderStyle="solid" borderColor="red"
> horizontalScrollPolicy="off" verticalScrollPolicy="off">
>                                <mx:Button label="Test" width="400" 
> height="400"/>
>                        </mx:VBox>
>                </view:ScaleOrCenterView>
>
>
>                [DefaultProperty("content")]
> public class ScaleOrCenterView extends UIComponent
>        {
>                private var _contentHolder:ScaleToFitContentHolder = new
> ScaleToFitContentHolder();;
>                private var _content:UIComponent;
>
>                public function ScaleOrCenterView()
>                {
>                        super();
>                }
>
>                override protected function createChildren():void {
>                        super.createChildren();
>                        this.addChild(_contentHolder);
>                }
>
>                [Inspectable]
>                public function set content(value:UIComponent):void {
>                        if (_content != null) {
>                                _contentHolder.removeChild(_content);
>                        }
>                        _content = value;
>                        if (_content != null) {
>                                _contentHolder.addChild(_content);
>                        }
>                        this.invalidateSize();
>                }
>
>                override protected function 
> updateDisplayList(unscaledWidth:Number,
> unscaledHeight:Number):void
>                {
>                        super.updateDisplayList(unscaledWidth, unscaledHeight);
>
>                        var contentWidth:Number = 
> _content.getExplicitOrMeasuredWidth();
>                        var contentHeight:Number = 
> _content.getExplicitOrMeasuredHeight();
>
>                        var xScale:Number = (unscaledWidth / contentWidth);
>                        var yScale:Number = (unscaledHeight / contentHeight);
>
>                        _contentHolder.setActualSize(unscaledWidth, 
> unscaledHeight);
>
>                        _contentHolder.allowInvalidateSize = false;
>                        if (xScale < 1 || yScale < 1) {
>                                _contentHolder.scaleX = xScale
>                                _contentHolder.scaleY = yScale
>                        } else {
>                                _contentHolder.scaleX = 1.0;
>                                _contentHolder.scaleY = 1.0;
>                        }
>                        _contentHolder.allowInvalidateSize = true;
>
>                }
>
>        }
>
> public class ScaleToFitContentHolder extends UIComponent
>        {
>                public var allowInvalidateSize:Boolean = true;
>
>                public function ScaleToFitContentHolder()
>                {
>                }
>
>                override protected function measure():void
>                {
>                        super.measure();
>                }
>
>            override public function invalidateSize():void
>            {
>                if (allowInvalidateSize)
>                    super.invalidateSize();
>            }
>
>        }
> On Mon, May 26, 2008 at 9:02 PM, Alex Harui <[EMAIL PROTECTED]> wrote:
>> One way is to block invalidateSize when scaling the child.  See
>> ListBaseContentHolder
>>
>>
>>
>> ________________________________
>>
>

Reply via email to