Skip to main content
Participant
February 12, 2007
Question

Code can't keep up with mouse

  • February 12, 2007
  • 3 replies
  • 294 views
Hi, I have Flash 8 Pro on Mac OS X Tiger 10.4

I have a movie clip with buttons inside it, and the mc must respond to mouse over, at which point it tweens to a different position on the Y axis.
I have a hitTest set onMouseMove but the menu breaks very, very easily - either by moving the mouse too quickly or by moving the mouse out of the stage area. It is crucial that the menu goes down whenever hitTest = false.

I've seen people achieve similar effects and they work flawlessly, I just can't imagine how it's done. Can anyone help please?
This topic has been closed for replies.

3 replies

Participant
February 13, 2007
Thanks for your help and patience kglad, I'm having trouble finding more information to try to solve this problem..

onEnterFrame = function() {
if(menu_mc.hitTest(_xmouse, _ymouse, false)) {
menu_mc._yscale = 600;
trace("true");
}
else {
menu_mc._yscale = 100;
trace("false");
}
}

This is the simplest piece of code I could think of based on your advice and it suffers from the exact same problem - mouse out too quickly and the menu stays in the open position. I think the problem is that hitTest isn't actually returning as false here, the 'if' statement is.. does that sound correct?
kglad
Community Expert
Community Expert
February 14, 2007
you can speed the frequency of hitTest checks up to approximately 1 ms (as opposed to the usual 85 ms with the default onEnterFrame):

kglad
Community Expert
Community Expert
February 13, 2007
using onEnterFrame has nothing to do with the number of frames in your swf. in particular, a one frame swf will execute an onEnterFrame loop without issue.

and yes, that's the point: an onEnterFrame loop or setInterval loop continue to execute no matter the location of the mouse and using a hitTest will be accurate no matter the location of the mouse. both of those are problems (mouse location and detecting mouse movement) with your code.
kglad
Community Expert
Community Expert
February 12, 2007
set up your conditional to check for a negative or positive hitTest and use a setInterval() or onEnterFrame loop.
Participant
February 13, 2007
my movie is a single frame.. the menu is fairly complex, so I coded it into a seperate movie. When the main movie first loads, I have an mc on the stage which the menu is loaded into.. then all code refers to that mc. I've always preferred to create single frame movies, they're easier to keep track of, so I don't have much experience with onEnterFrame - is there any advantage to that over onMouseMove? Is it possible that it is onMouseMove that is killing me - because this cannot be tested while mouse is out of the movie area?