• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Zoom to the mouse position

New Here ,
Aug 03, 2015 Aug 03, 2015

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

TOPICS
ActionScript

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 05, 2015 Aug 05, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 05, 2015 Aug 05, 2015

Copy link to clipboard

Copied

LATEST

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:

https://github.com/ElliotMebane/FlashZoom

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines