# Interactive Image Panning

**URL:** <https://forum.kirupa.com/t/interactive-image-panning/319937>\
**Category:** Uncategorized\
**Created:** [March 9, 2011, 11:25am UTC](https://forum.kirupa.com/t/interactive-image-panning/319937 "2011-03-09T11:25:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ctaminian](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@ctaminian](https://forum.kirupa.com/u/ctaminian)\
**Post date:** [March 9, 2011, 11:25am UTC](https://forum.kirupa.com/t/interactive-image-panning/319937/1 "2011-03-09T11:25:43Z")

</div>

Hello,

I’ve been following the tutorial provided here on KIRUPA regarding the interactive image panning…the link is bellow

[http://www.kirupa.com/developer/flash8/interactive\_image\_pan.htm](http://www.kirupa.com/developer/flash8/interactive_image_pan.htm)

I have edited the code to make it work for both x and y directions…

It works like a charm…but i’m trying to reduce the distance it travels to about half or a quarter…I don’t want it to scroll all the way to the image’s bounds…I want it to move to about a fraction of that distance…

Can anyone help me please!!!

Here’s the code I modified…

```php

this.onMouseMove = function()
{
    constrainedMove(mc2,2,1);
};
function constrainedMove(target:MovieClip, speed:Number, dir:Number)
{
    var mousePercent:Number = _xmouse / Stage.width;
    var mousePercentY:Number = _ymouse / Stage.height;
    var mSpeed:Number;
    var mSpeedY:Number;
    if (dir == 1)
    {
        mSpeed = mousePercent;
        mSpeedY = mousePercentY;
    }
    else
    {
        mSpeed = 1 - mousePercent;
        mSpeedY = 1 - mousePercentY;
    }
    target.destX = Math.round(-((target._width - Stage.width) * mSpeed));
    target.destY = Math.round(-((target._height - Stage.height) * mSpeedY));
    
    target.onEnterFrame = function()
    {
        if (target._x == target.destX)
        {
            delete target.onEnterFrame;
        }
        else
        {
            target._x += Math.ceil((target.destX - target._x) * (speed / 100));
        }

        if (target._y == target.destY)
        {
            delete target.onEnterFrame;
        }
        else
        {
            target._y += Math.ceil((target.destY - target._y) * (speed / 100));
        }
    };
}

```
