我正在尝试根据movieclip的x和y位置缩放基本图像?基本图像图像也是MC。
infoIconCompFit.addEventListener(MouseEvent.ROLL_OVER, zoomInCompFit);
infoIconCompFit.addEventListener(MouseEvent.ROLL_OUT, zoomOutCompFit);
function zoomInCompFit(event:MouseEvent):void {
TweenLite.to(baseImage, 1, {scaleX:2, scaleY:2});
}
function zoomOutCompFit(event:MouseEvent):void {
TweenLite.to(baseImage, 1, {scaleX:1, scaleY:1});
}
我的意思是;是否可以在舞台上的另一个动画片段的x和y位置缩放动画片段?就像我希望基本的动画片段在鼠标ROLL_OVER上的另一个动画片段的位置缩放(放大)然后缩小鼠标ROLL_OUT。
我将它放到处理器放大和缩小的位置,但是如何让它相对于其他MC放大??
(之前)http://www.marketingfanatics.co.za/images/exampleNormal.jpg (之后)http://www.marketingfanatics.co.za/images/exampleZoomedl.jpg
答案 0 :(得分:0)
是的,你可以。但是你需要编写一些代码并记住这些对象的转换枢轴。
/**
* Calculate position and dimensions of image to zoom.
* @param img - image to animate, need to have transformation pivot in top left corner!
* @param point - point to zoom in (or null if zoom out) that will be new center of image
* @param scale - scale in zoom in
* @param viewWidth - container width
* @param viewHeight - container height
* @return object for tween engine with parameters to animate
*/
private function centerOn(img:DisplayObject, point:Point=null, scale:Number=2, viewWidth:Number=300, viewHeight:Number=200):Object
{
var r:Object;
var mm:Matrix = img.transform.matrix;
img.transform.matrix = new Matrix();
if (point == null) { // oryginal size
r = { x: 0, y: 0, width: img.width, height: img.height };
}else { // zoom
img.scaleX = img.scaleY = scale;
point.x *= scale;
point.y *= scale;
img.x = -point.x + viewWidth / 2;
img.y = -point.y + viewHeight / 2;
r = { x: img.x, y: img.y, width: img.width, height: img.height };
}
img.transform.matrix = mm;
return r;
}
使用示例:
TweenLite.to(baseImage, 1, centerOn(baseIMG, new Point(100, 150))); //zoom in
TweenLite.to(baseImage, 1, centerOn(baseIMG)); //zoom out
centerOn(img, new Point(200, 135), 4, stage.stageWidth, stage.stageHeight); // to fit stage size
请记住,您的显示对象未被屏蔽,有时(在边框附近缩放)您将看到它下面的场景!
PS。代码测试。