Copy link to clipboard
Copied
Hello!
Ive got this code for zoom, but its zoom to the center of the image, but i would like to zoom to the mouse position. HELP ME PLEASE!
import flash.events.MouseEvent;
stage.addEventListener(MouseEvent.MOUSE_WHEEL, Zoom);
function Zoom(e:MouseEvent):void
{
var mod:Number = 20;
kep2.scaleX += e.delta / mod;
kep2.scaleY += e.delta / mod;
if(kep2.scaleX<1){
kep2.scaleX=kep2.scaleY=1;
}
kep2.scaleX *= Math.max(scaleY,scaleX);
kep2.scaleY *= Math.max(scaleX,scaleY);
THANKS FOR YOUR HELP
Copy link to clipboard
Copied
To zoom to any position requires the object being zoomed to have its registration mark at that point. Usually when you zoom something you place it inside another container object and then zoom (scale) the container rather than the visual object you wish to give the impression of zooming. To be able to zoom where the mouse is pointing will require you to simultaneously move the container's registration to the mouse while adjusting the position of the visual object so that it does not appear to move as the object that contains it is moved. When a zoom is about to commence you will first need to determine what changes in x/y must happen for the container to move to the cursor location and then adjust the x/y position of the visual in the opposite of that as soon as you move the container.
Copy link to clipboard
Copied
Here's a Zoom class I made long ago. It allows zooming around an anchor point.
Functional Sample:
http://www.roguish.com/lab/zoom/gitHub/zoom_CS5.html
GitHub: