# Following my mouse movements from within a movie

**URL:** https://forum.kirupa.com/t/following-my-mouse-movements-from-within-a-movie/2606
**Category:** Uncategorized
**Created:** [May 22, 2002, 2:32pm UTC](https://forum.kirupa.com/t/following-my-mouse-movements-from-within-a-movie/2606 "2002-05-22T14:32:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 22, 2002, 2:32pm UTC](https://forum.kirupa.com/t/following-my-mouse-movements-from-within-a-movie/2606/1 "2002-05-22T14:32:26Z")

</div>

hello!

i’ve got a little actionscript that makes a shape follow my mouse about the screen. it works fine when i place it in a layer. however, when the code is in a mc and i place the mc in my layer, then i get no joy

i expect i need a line like tellTarget when using buttons within a mc to target places outside the mc?

any helps is appreciated

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 23, 2002, 4:19am UTC](https://forum.kirupa.com/t/following-my-mouse-movements-from-within-a-movie/2606/2 "2002-05-23T04:19:57Z")

</div>

You probebly need to change a small piece of the code.

What is the code you currently are using for the “follow”?

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 24, 2002, 5:43am UTC](https://forum.kirupa.com/t/following-my-mouse-movements-from-within-a-movie/2606/3 "2002-05-24T05:43:56Z")

</div>

i have a graphic named box and an empty movie clip with 2 frames

frame1:

if (\_root.\_xmouse\>\_level0.box.\_x) {  
&nbsp &nbsp &nbsp &nbsp \_level0.box.\_x = (\_level0.box.\_x+10);  
} else {  
&nbsp &nbsp &nbsp &nbsp \_level0.box.\_x = (\_level0.box.\_x-10);  
}

* * *

frame2:

if (\_root.\_xmouse\>\_level0.box.\_x) {  
&nbsp &nbsp &nbsp &nbsp \_level0.box.\_x = (\_level0.box.\_x+10);  
} else {  
&nbsp &nbsp &nbsp &nbsp \_level0.box.\_x = (\_level0.box.\_x-10);  
}  
gotoAndPlay (1);

PS i found the example on the net, so i’ve no idea if this is the best way of doing things

cheers  
🙂

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 24, 2002, 6:00am UTC](https://forum.kirupa.com/t/following-my-mouse-movements-from-within-a-movie/2606/4 "2002-05-24T06:00:23Z")

</div>

well you could try it like this…

frame1:

if (\_parent.\_xmouse\>\_parent.box.\_x) {  
\_parent.box.\_x = (\_parent.box.\_x+10);  
} else {  
\_parent.box.\_x = (\_parent.box.\_x-10);  
}

* * *

frame2:

if (\_parent.\_xmouse\>\_parent.box.\_x) {  
\_parent.box.\_x = (\_parent.box.\_x+10);  
} else {  
\_parent.box.\_x = (\_parent.box.\_x-10);  
}  
gotoAndPlay (1);

but personaly I would do it like this.

take the same box and place it on the stage in a new blank layer. Select it, and check it out in the “instance” panel. If it is there and lists it as a movie clip, you can do this trick… If not, switch it to a movie clip in the instance panel. It will work just as well.

Now you just select it, open the “action” panel, and type in the following.

onclipEvent(enterFrame){  
diff=\_x-\_root.mouse;  
\_x+=diff/4;  
}

you can change the rate of movement by dividing the diff by higher and higher numbers.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [May 27, 2002, 2:31pm UTC](https://forum.kirupa.com/t/following-my-mouse-movements-from-within-a-movie/2606/5 "2002-05-27T14:31:09Z")

</div>

superb!  
you make it look easy! 😛

the reason i wanted this feature inside a movieclip and not directly on the layer is bacause the mc is the whole gui (which i place on the layer), and in that gui ther are 4 buttons in a corner - and i only want the shape-that-follows-the-mouse to happen in that corner of the screen. but i can set it up on the layer and just use a mask around the corner of the screen (the gui mc, when placed on the layer) where the buttons appear

🙂

cheers!
