# onMouseMove

**URL:** <https://forum.kirupa.com/t/onmousemove/5657>\
**Category:** flash\
**Created:** [September 18, 2002, 9:35pm UTC](https://forum.kirupa.com/t/onmousemove/5657 "2002-09-18T21:35:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![j0se](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/j0se/32/44_2.png) [@j0se](https://forum.kirupa.com/u/j0se)\
**Post date:** [September 18, 2002, 9:35pm UTC](https://forum.kirupa.com/t/onmousemove/5657/1 "2002-09-18T21:35:02Z")

</div>

i want the playhead to shift a frame each time i move my mouse over a certain area, but the following code is making this happen when i move my mouse anywhere on the stage

onClipEvent (mouseMove) {  
\_root.myClip.nextFrame();  
}

can i specify coordinates?

i tried using rollOver instead, but of course, this only moves the playhead once and i have to roll out of teh object in order to create a new rollOver event

as always, thanks

---

<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:** [September 18, 2002, 10:13pm UTC](https://forum.kirupa.com/t/onmousemove/5657/2 "2002-09-18T22:13:38Z")

</div>

Try:

onClipEvent (enterFrame) {  
if (this.hitTest(\_root.\_xmouse, \_root.\_ymouse, true) {  
\_root.myClip.nextFrame();  
}

Haven’t tested it yet - should work.

---

<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:** [September 18, 2002, 10:19pm UTC](https://forum.kirupa.com/t/onmousemove/5657/3 "2002-09-18T22:19:29Z")

</div>

It will work on a movie clip. So put whatever you want the mouse to be over, in a movie clip, then give the mc the above actions.

---

<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:** [September 18, 2002, 11:26pm UTC](https://forum.kirupa.com/t/onmousemove/5657/4 "2002-09-18T23:26:07Z")

</div>

yeah that should work…you didn’t have anything to stop it from doing the action when the mouse wasn’t over 🙂

---

<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:** [September 19, 2002, 5:09am UTC](https://forum.kirupa.com/t/onmousemove/5657/5 "2002-09-19T05:09:00Z")

</div>

how about

onClipEvent (mouseMove) {  
if (\_root.\_xmouse\>200) {  
\_root.myClip.nextFrame();  
}else if (\_root.\_xmouse\<100){  
\_root.myClip.previousFrame();  
}  
}

or something to that effect.

I don’t think this is an optimal way of doing this effect though… I guess I would need to know how this is being used before I could come up with something that might work well. mouseMoves can be nice because they free up processor power from doing enterFrame effects, but they are cumbersome in how they operate.

I guess my questions would be:  
do you want it to only go one frame per time it’s placed on the spot?  
and  
is the spot an area on the stage, or just a matter of left of center/right of center kind of thing?

---

<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:** [September 19, 2002, 5:30am UTC](https://forum.kirupa.com/t/onmousemove/5657/6 "2002-09-19T05:30:07Z")

</div>

just my two cents…

```auto

theMovie.onRollOver = function(){
   this.onMouseMove = this.nextFrame;
}

theMovie.onRollOut = function(){
   this.onMouseMove = null;
}

```

_edited to make shorter_

---

<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:** [September 19, 2002, 5:41am UTC](https://forum.kirupa.com/t/onmousemove/5657/7 "2002-09-19T05:41:17Z")

</div>

nice… does it work in 5.0 or MX or both?

---

<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:** [September 19, 2002, 5:42am UTC](https://forum.kirupa.com/t/onmousemove/5657/8 "2002-09-19T05:42:43Z")

</div>

mx only, i’m afraid.

the event engine is one of my favourite additions…

---

<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:** [September 19, 2002, 5:56am UTC](https://forum.kirupa.com/t/onmousemove/5657/9 "2002-09-19T05:56:19Z")

</div>

I wish you guys would remember to put that in your posts. 🙂

It is REALLY nice to see how much smaller the coding is becoming in the new version of Flash though.

---

<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:** [September 19, 2002, 9:06am UTC](https://forum.kirupa.com/t/onmousemove/5657/10 "2002-09-19T09:06:17Z")

</div>

ok,

flex’s code did the trick:  
onClipEvent (enterFrame) {  
if (this.hitTest(\_root.\_xmouse, \_root.\_ymouse, true) {  
\_root.myClip.nextFrame();  
}

and david took it a stage further with the addition of prevFrame(), which i hadn’t thought about!!

what i want to do is this: i have a ‘viewing’ area on the stage, where i’m going to insert a clip containing a sequence of images that, when run one after the other, give the impression of video-like movement

i’m going to place an invisible button over that viewing area and insert the code in question, so that when the cursor moves over the button… you get the video-motion

i saw this in a great site (i can’t find the url or i would post it) and i fell in love with the effect

thanks for all that  
🙂

PS sbeener’s code is very compact!! i’ll have to meddle with it  
🙂

---

<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:** [September 19, 2002, 11:07am UTC](https://forum.kirupa.com/t/onmousemove/5657/11 "2002-09-19T11:07:24Z")

</div>

yeah… if that’s what you’re trying to do, I’d definitely ignore my post and go with the enterFrame method discribed by Flex. I was just trying to save you some processor power. The enterFrame method though will provide smooth frame by frame, even if the person stops moving their mouse. (onMouseMove only works when the mouse is actually in motion)

glad you got it working… sounds like a neat effect. Please try to remember to give us a link to check it out once you’ve got all the bugs out. 🙂

---

<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:** [September 19, 2002, 10:40pm UTC](https://forum.kirupa.com/t/onmousemove/5657/12 "2002-09-19T22:40:42Z")

</div>

ok, i’m still having a few snags… i spoke too soon (before i tried the code)

here’s a link to what i’m working on:  
[http://www.alt-student.co.uk/flash/1.htm](http://www.alt-student.co.uk/flash/1.htm)  
(that’s not me, btw - it’s my son)  
🙂

the ‘movie’ is a sequence of pics with a gotoAndStop(1); on the last frame (so you see it run once on load)

the code on the movie instance is:

onClipEvent(mouseMove){  
if (this.hitTest(\_root.\_xmouse, \_root.\_ymouse, true)){  
\_root.myClip.nextFrame();  
}  
}

the prob is that the movie only plays forward

david: i tried your code:

onClipEvent (mouseMove) {  
if (\_root.\_xmouse\>200) {  
\_root.myClip.nextFrame();  
}else if (\_root.\_xmouse\<100){  
\_root.myClip.previousFrame();  
}  
}

it does what i need it to do, but i don’t know how to work out the x and y coordinates of my movie (so that it works properly)

and finally, here’s the link to the site where i saw the effect (i found the url)

[http://www.yulia-nau.de/eng.htm](http://www.yulia-nau.de/eng.htm)

---

<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:** [September 19, 2002, 10:56pm UTC](https://forum.kirupa.com/t/onmousemove/5657/13 "2002-09-19T22:56:16Z")

</div>

I modified an image scroller I did for some at Kirupa. This should work:

EDIT: Changed the fla brought the boundaries closer.

---

<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:** [September 20, 2002, 12:57am UTC](https://forum.kirupa.com/t/onmousemove/5657/14 "2002-09-20T00:57:12Z")

</div>

It’s the same as the code David posted, just in onClipEvent(enterFrame). It moves the animation forward while the mouse is held in a certain place, and moves the animation back, if held in another. If you wanted to the animation to play when the mouse was dragged - use David’s code (the on mouse move).

---

<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:** [September 20, 2002, 8:03am UTC](https://forum.kirupa.com/t/onmousemove/5657/15 "2002-09-20T08:03:01Z")

</div>

got it!

i woke up this morning, stared at the ceiling and thought: info panel, cente/left grid…

i don’t know why this eluded me last night - ok, so the coordinates are no prob

cheers flex for the zip: it’s interesting to see how somebody else does things - i.e. i thought of using a video file and placing a stop action on each keyframe (as opposed to using a sequence of images) but i wondered whether that was a good way to do things

i suppose the video file will be much bigger but it would be interesting to see how it responds - you might get some blurring between stops in framesm but that ight look good (i’ll give it a try later)

did you check that site out?

---

<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:** [September 20, 2002, 8:16am UTC](https://forum.kirupa.com/t/onmousemove/5657/16 "2002-09-20T08:16:48Z")

</div>

actually, having tried the code and looking back at the original effect i can see that i misunderstood some of the mechanics

ok - this might be voodoo and maybe a different object with the right methods is required, but this is the functionality i was after:

===  
if the mouse moves to the right, then nextFrame();

# if the mouse moves to the left, then prevFrame();

please don’t think the previous stuff was a waste of time! it’s given me the foundation to see this far!  
🙂

---

<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:** [September 20, 2002, 9:05am UTC](https://forum.kirupa.com/t/onmousemove/5657/17 "2002-09-20T09:05:52Z")

</div>

see [http://www.kirupaforum.com/showthread.php?s=&threadid=6435](http://www.kirupaforum.com/showthread.php?s=&threadid=6435)

🙂

---

<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:** [September 20, 2002, 9:38am UTC](https://forum.kirupa.com/t/onmousemove/5657/18 "2002-09-20T09:38:51Z")

</div>

very nicely written - we often forget ‘how we work’ when busy trying to solve ‘how things work’

at my level though, i’d be asleep for most of the day!  
😛

i shall work/sleep on it

funnily enough, i’m finding that the more time i spend sitting around visualising a site, the less time i spend at the PC

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:** [September 20, 2002, 10:49am UTC](https://forum.kirupa.com/t/onmousemove/5657/19 "2002-09-20T10:49:07Z")

</div>

that is very true too. my current site, [animation.centerspin.com](http://animation.centerspin.com) consists of:

32 3/5 cards with notes.  
1 steno of various tested and partial code.  
1 steno containing names of movie clips, variables, arrays, xml docs, text docs, etc  
42 sheets of white scrap paper with sketches of sections or clips.  
3 sheets of white paper containing a flow chart.

And that site is small compared to a real commercial site. I can only imagine how complex that must get.

---

<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:** [September 20, 2002, 11:58am UTC](https://forum.kirupa.com/t/onmousemove/5657/20 "2002-09-20T11:58:47Z")

</div>

I was thinking of somehow (I was trying to figure it out last night) using getTimer() to check the current \_xmouse to the \_xmouse 0.5 or 0.25 seconds ago and if it was \> x nextFrame(); and if it was \< x prevFrame();.

[Next page](https://forum.kirupa.com/t/onmousemove/5657.md?page=2)
