# Making a sprite move to mouse click

**URL:** <https://forum.kirupa.com/t/making-a-sprite-move-to-mouse-click/194604>\
**Category:** flash\
**Created:** [July 24, 2006, 10:09pm UTC](https://forum.kirupa.com/t/making-a-sprite-move-to-mouse-click/194604 "2006-07-24T22:09:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_flash](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@john\_flash](https://forum.kirupa.com/u/john_flash)\
**Post date:** [July 24, 2006, 10:09pm UTC](https://forum.kirupa.com/t/making-a-sprite-move-to-mouse-click/194604/1 "2006-07-24T22:09:36Z")

</div>

Do you want to make a movieClip move to any point you click on the screen and are tired of all the Math.functions?Well,this is it.  
First,draw your character i just used a square.  
Convert it to a movieclip,name it whatever you like.No instance name needed for the square.draw a very small circle,this is to detect the mouse angle.Convert your small circle to a movieClip and give it the instance name"mu".Now lets move to the coding aspect,dont be scared,just a few if() statements and variables.thats all.Select your “mu” movieclip(small circle) and paste the following code:

onClipEvent (mouseDown) {:diss:  
\_x = \_root.\_xmouse;  
\_y = \_root.\_ymouse;  
}

Go to your sprite movieClip and enter the follwoing:

onClipEvent (load) {  
mu = \_root.go;  
speed = 5;  
}  
onClipEvent (enterFrame) {  
if (\_x\<mu.\_x) {  
\_x +=speed;  
}  
if (\_x\>mu.\_x) {  
\_x -=speed;  
}  
if (\_y\>mu.\_y) {  
\_y -=speed;  
}  
if (\_y\<mu.\_y) {  
\_y +=speed;  
}  
}

Thats it all.  
Hope its okay for a thirteen-yearold
