# Mouse updating, Please Help

**URL:** <https://forum.kirupa.com/t/mouse-updating-please-help/277012>\
**Category:** flash\
**Created:** [December 6, 2008, 4:57am UTC](https://forum.kirupa.com/t/mouse-updating-please-help/277012 "2008-12-06T04:57:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![justinf](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@justinf](https://forum.kirupa.com/u/justinf)\
**Post date:** [December 6, 2008, 4:57am UTC](https://forum.kirupa.com/t/mouse-updating-please-help/277012/1 "2008-12-06T04:57:14Z")

</div>

I’m doing an assignment where I need to have a ball move to the side of the screen that the mouse is on. However, I’ve gotten stuck, when the mouse stops moving the ball stops moving. I think it’s because the listener isn’t being activated, so i’ve tried adding another listener for ENTER\_FRAME, but I can’t get it to work. I’ve looked around and I can’t find a solution, any help would be awesome. I’ve commented out the ENTER\_FRAME listener stuff to make it work.

var ball:Ball = new Ball();  
var updateMouseX:Number;  
var updateMouseY:Number;  
var moving:Boolean = true;  
stage.addChild(ball);  
ball.x = 0;  
ball.y = 200;

[//stage.addEventListener](https://stage.addEventListener)(Event.ENTER\_FRAME, enterframe);

stage.addEventListener(MouseEvent.MOUSE\_MOVE, mousePos);

//addEventListener(Event.ENTER\_FRAME,myfunction);

/_function myFunction(event:Event){  
mousePos(event:MouseEvent);  
}_/

function mousePos(event:MouseEvent){  
updateMouseX = event.localX;  
updateMouseY = event.localY;  
ballmove(updateMouseX, updateMouseY);  
}

function ballmove(updateMouseX, updateMouseY){  
if(updateMouseX \>= 400 && ball.x \< 600){  
ball.x += 5 ;  
}  
if(updateMouseX \<= 200 && ball.x \> 0){  
ball.x -= 5 ;  
}  
if(updateMouseY \>= 400 && ball.y \< 600){  
ball.y += 5 ;  
}  
if(updateMouseY \<= 200 && ball.y \> 0){  
ball.y -= 5 ;  
}  
}
