放大和缩小AS3 [英] Zooming in and out in AS3
问题描述
我正在制作一个文件,该文件需要能够使用鼠标中键滚动放大和缩小图像(转换为符号并指定实例名称).我写过类似的东西:
I'm making a file where I need to be able to zoom in and out on an Image (Converted to a symbol and given an instance name) using the middle mouse scroller. I've written something similar to :
image1.addEventListener(MouseEvent.MOUSE_WHEEL, function1){
image1 = image 1 +50;
}
因此所有滚动都可以增加图像的大小,但是如果我向后滚动鼠标滚轮,它将滚动出图像,该怎么做呢? 据我了解,MOUSE_WHEEL没有相反的操作.
so all the scrolling works to increase the image size, but what can I do to make it where if I scroll back the mouse wheel, it scrolls out of the image? From what I understand, there is no converse operation to MOUSE_WHEEL.
推荐答案
MouseEvent :: delta 指示用户旋转鼠标滚轮的每个单位应滚动多少行.正增量值表示向上滚动;正值表示向上滚动.负值表示向下滚动.
MouseEvent::delta Indicates how many lines should be scrolled for each unit the user rotates the mouse wheel. A positive delta value indicates an upward scroll; a negative value indicates a downward scroll.
检查事件增量值是正还是负,并使用scaleX和scaleY缩放图像.
Check if event delta value is positive or negative and scale the image using scaleX and scaleY.
var zoomAmount:Number = 0.1;
stage.addEventListener(MouseEvent.MOUSE_WHEEL, zooom);
function zoom(event:MouseEvent):void {
if(event.delta > 0) {
image1.scaleX += zoomAmount;
image1.scaleY += zoomAmount;
} else {
image1.scaleX -= zoomAmount;
image1.scaleY -= zoomAmount;
}
}
这篇关于放大和缩小AS3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!