# Mouse movement background

**URL:** <https://forum.kirupa.com/t/mouse-movement-background/281382>\
**Category:** Uncategorized\
**Created:** [February 8, 2009, 6:13pm UTC](https://forum.kirupa.com/t/mouse-movement-background/281382 "2009-02-08T18:13:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![flashera](https://avatars.discourse-cdn.com/v4/letter/f/9d8465/32.png) [@flashera](https://forum.kirupa.com/u/flashera)\
**Post date:** [February 8, 2009, 6:13pm UTC](https://forum.kirupa.com/t/mouse-movement-background/281382/1 "2009-02-08T18:13:06Z")

</div>

Hi,

I am doing a website where the background is moved with the mouse horizontally. I want it with a edge size ti avoid too much movement when the mouse is in the middle of the stage.  
I followed a AS3 tutorial but I am working with AS2, then this with my not very good SA knoleadge is getting me mad. THis is the code

var mousePositionX:Number = 0;  
var speedX:Number = 0;  
var edge:Number = 100;  
var scrollDivide:Number = 10;  
stage.addEventListener(Event.ENTER\_FRAME, calculate);  
function calculate(Event) {  
mousePositionX = \_xmouse;  
// Left edge.  
if (mousePositionX \>= 0 && mousePositionX \< edge) {  
speedX = (edge - mousePositionX) / scrollDivide;  
scroller.\_x = Math.min(scroller.\_x + speedX, 0);  
}  
// Right edge.  
else if (mousePositionX \>= (Stage.width- edge) && mousePositionX \< Stage.width) {  
speedX = (mousePositionX - (Stage.width - edge)) / scrollDivide;  
scroller.\_x = Math.max(scroller.\_x - speedX, Stage.width - scroller.\_width);  
}  
// The middle.  
else {  
}  
}

Somebody could help me with that?

Thanks
