zoom使用transform.matrix缩放flex组件

时间:2011-07-08 15:40:47

标签: flash flex actionscript zoom transform

有人可以告诉我如何使用transform.matrix缩放Canvas,以便组件的内容适合父容器(应用程序),向内或向外

这个函数叫做Zoomfit(),我有这个代码:

    public function calcScaleToFitRatio(parentObj:DisplayObject, childObj:DisplayObject):Number{
    var retVal:Number = 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;
}

但我无法应用于matrix.scale();

1 个答案:

答案 0 :(得分:1)

这样的东西可行,显然用您正在伸展的容器名称替换stretchedCanvas

    <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>