开发者

zoom fit a flex component with transform.matrix

someone could tell me how I can zoom a Canvas, with transform.matrix, so that the content of the component fits into the parent container (application), either inward or outward

this function is called Zoomfit(), I have this code:

    public function calcScaleToFitRatio(parentObj:DisplayObject, childObj:DisplayObject):Number{
    var retVal:Number =开发者_StackOverflow社区 1;
    if (null == childObj) {
        return 1;
    }
    var containerRatio:Number     = parentObj.height  / parentObj.width;
    var contentsRatio:Number      = childObj.height   / childObj.width;
    var isContainerLarger:Boolean = (containerRatio > contentsRatio);
    if (true === isContainerLarger) {
        retVal = parentObj.width / childObj.width;
    } else {
        retVal = parentObj.height / childObj.height;
    }
    return retVal;
}

But I can't applied to matrix.scale();


Something like this would work, obviously replace stretchedCanvas with name of your container you're stretching.

    <mx:Canvas width="600">   <!-- outer container -->
        <mx:Canvas id="stretchedCanvas" 
            scaleX="{IContainer(stretchedCanvas.parent).width/stretchedCanvas.width}"
            scaleY="{IContainer(stretchedCanvas.parent).height/stretchedCanvas.height}"
        >
        </mx:Canvas>
    </mx:Canvas>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜