# How to make a movie clip repel the cursor

**URL:** <https://forum.kirupa.com/t/how-to-make-a-movie-clip-repel-the-cursor/293104>\
**Category:** Uncategorized\
**Created:** [July 23, 2009, 8:29am UTC](https://forum.kirupa.com/t/how-to-make-a-movie-clip-repel-the-cursor/293104 "2009-07-23T08:29:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dukeofhazard69](https://avatars.discourse-cdn.com/v4/letter/d/a87d85/32.png) [@dukeofhazard69](https://forum.kirupa.com/u/dukeofhazard69)\
**Post date:** [July 23, 2009, 8:29am UTC](https://forum.kirupa.com/t/how-to-make-a-movie-clip-repel-the-cursor/293104/1 "2009-07-23T08:29:42Z")

</div>

Hi, having trouble with this .fla (attached) i have an object on the stage and I want to be able to make it repel the mouse cursor, similar to a magnet, so you cant get near it…

The MC is called BOX and this code I have on the frame…

var dist = 30;  
var objx = box.\_x += (box.\_width/2);  
var objy = box.\_y += (box.\_height/2);

if(\_xmouse \> (objx -= dist) && \_xmouse \< (objx += dist) && \_ymouse \> (objy -= dist) && \_ymouse \< (objy += dist)) {  
box.\_x = Math.ceil(Math.random() \* Stage.width;  
box.\_y = Math.ceil(Math.random() \* Stage.height;  
}

But doesn’t seem to work… Any help much appreciated.
