# Panning a background in AS2

**URL:** <https://forum.kirupa.com/t/panning-a-background-in-as2/285599>\
**Category:** Uncategorized\
**Created:** [April 2, 2009, 7:43pm UTC](https://forum.kirupa.com/t/panning-a-background-in-as2/285599 "2009-04-02T19:43:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pietern](https://avatars.discourse-cdn.com/v4/letter/p/c67d28/32.png) [@pietern](https://forum.kirupa.com/u/pietern)\
**Post date:** [April 2, 2009, 7:43pm UTC](https://forum.kirupa.com/t/panning-a-background-in-as2/285599/1 "2009-04-02T19:43:53Z")

</div>

Hi everybody,

from an example here on [Kirupa.com](http://Kirupa.com) I am trying to figure out how to pan a background.  
The example I took explains very well how it works but only with the X coordinate, I added  
now an Y-coordinate but because I am still learning to understand Scripting I get into trouble.

With the y-coordinate added to the function triggered by onMouseMove the background will only pan according the second parameter. When I switch the second parameter in the function off in the function the background will work with the first. So far I think that it is not possible to add two parameters this way to the function, but I dont’ know how to solve this. I have a notion where the problem is but I don’t know how to solve it.

Is there a more simple way of doing this? And if not what is the best way to solve this.

here is my actionscript:

```auto
this.onMouseMove = function (){
	constrainedMove(bg_mc, 10, 1);
	constrainedMoveY(bg_mc, 10, 1);
}

function constrainedMove(target:MovieClip, speed:Number, dir:Number) {
	var mousePercent:Number = _xmouse/Stage.width;
	var mSpeed:Number;
	if (dir == 1) {
		mSpeed = 1-mousePercent;
	} else {
		mSpeed = mousePercent;
	}
	target.destX = Math.round(-((target._width-Stage.width)*mSpeed));
	target.onEnterFrame = function() {
		if (target._x == target.destX) {
			delete target.onEnterFrame;
		} else if (target._x>target.destX) {
			target._x -= Math.ceil((target._x-target.destX)*(speed/100));
		} else if (target._x<target.destX) {
			target._x += Math.ceil((target.destX-target._x)*(speed/100));
		}
	}
}
function constrainedMoveY(target:MovieClip, speed:Number, dirY:Number) {
	var mousePercentY:Number = _ymouse/Stage.height;
	var mSpeed:Number;
	if (dirY == 1) {
		mSpeed = 1-mousePercentY;
	} else {
		mSpeed = mousePercentY;
	}
	target.destY = Math.round(-((target._height-Stage.height)*mSpeed));
	target.onEnterFrame = function() {
		if (target._y == target.destY) {
			delete target.onEnterFrame;
		} else if (target._y>target.destY) {
			target._y -= Math.ceil((target._y-target.destY)*(speed/100));
		} else if (target._y<target.destY) {
			target._y += Math.ceil((target.destY-target._Y)*(speed/100));
		}
	}
}

```

thanks in advance
