# Help with zoom function

**URL:** <https://forum.kirupa.com/t/help-with-zoom-function/170905>\
**Category:** flash\
**Created:** [November 30, 2005, 12:36pm UTC](https://forum.kirupa.com/t/help-with-zoom-function/170905 "2005-11-30T12:36:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerry](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jerry](https://forum.kirupa.com/u/jerry)\
**Post date:** [November 30, 2005, 12:36pm UTC](https://forum.kirupa.com/t/help-with-zoom-function/170905/1 "2005-11-30T12:36:09Z")

</div>

Hey kirupa people 🙂

The following code (applied to a movieclip) let’s you scale (‘zoom’) the \_root of the stage on mouseDown:

```auto
onClipEvent (load) {
var dir;
var pt;
var zoom;
k = 0;
}
onClipEvent (mouseDown) {
        if(this.hitTest(_root._xmouse, _root._ymouse, true)){
                if (k>0) {
                        return;
                }
                zoom = true;
                dir == 1 ? (dir=-1) : (dir=1);
				
                if (dir == 1) {
                        pt = {x:_root._xmouse, y:_root._ymouse};
                }
        }
}
onClipEvent (enterFrame) {
        if (!zoom) {
                return;
        }
        _root._xscale += dir*k*50/8;
        _root._yscale += dir*k*50/8;
        var pt2 = {x:pt.x, y:pt.y};
        _root.localToGlobal(pt2);
        _root._x -= (pt2.x-pt.x);
        _root._y -= (pt2.y-pt.y);
		
        k++;
        if (k == 7) { // how close
                zoom = false;
                k = 0;		
        }
}

```

Although the code may be a little ugly, it works :hugegrin:

So far I’m able to zoom in on a certain point on mouseDown, and again zoom out to the original point on mouseDown.

BUT, I need a ‘little’ help with the next step:  
What I would like to do is, zoom in, and then be able to move the stage around with the mouse\_x and mouse\_y - so that when I move my mouse to the left, the stage (\_root.\_x) moves to the right, etc…

Hope you understand what I’m saying…!? 🙂 - any help would be nice
