Zooming in and out in AS3

故事扮演 提交于 2020-01-16 09:44:07

问题


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

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.


回答1:


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.

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


来源:https://stackoverflow.com/questions/19877835/zooming-in-and-out-in-as3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!