Skip to main content
Walloompoom
Inspiring
July 12, 2006
Question

Mouse Stop

  • July 12, 2006
  • 5 replies
  • 889 views
Hi, I have a custom cursor that needs to know when the mouse stops but there is no onMouseStop. Is there a way to do it with the mouse listener?

Thanks! James

This topic has been closed for replies.

5 replies

Walloompoom
Inspiring
July 12, 2006
trace("Mouse stopped: " + bMouseIsStopped); returns true ONLY when you havent put the mouse on stage.
trace("Old Y Pos: " + yMousePos); and x are always undefined.
Known Participant
July 12, 2006
// Keep the new mouse position.
xMousePos = _xNewMousePos;
yMousePos = _yNewMousePos;

it's xNewMousePos not _xNewMousePos
same for y
Known Participant
July 12, 2006
Oops sorry for the indentation, I'll use "attach code" next time
Walloompoom
Inspiring
July 12, 2006
Hi. I tried it but the cursor doesnt react at all. Here is the full code


Known Participant
July 12, 2006
Ok many things could go wrong
where is that code exactly? on the main timeline?

make sure onEnterFrame is called everyframe by tracing _xmouse and _ymouse inside the function and making sure the mouse position is correct.
Also do this trace:
trace(!bMouseIsStopped && xNewMousePos == xMousePos && yNewMousePos == yMousePos);
you'll see a true pass by when the mouse stops if it's working well.

if it'S working well put a trace("OnMouseStop"); in the function OnMouseStop

Also trace (); probably won'T do much, use trace("InsideStopCondition"); or something like that to make the trace significant.

Basicly work your way through the code with traces and see where it stops working, trace the values of the variables you're using at different places to see where it stops being right.
Known Participant
July 12, 2006
Yeah do what EvilDog said. in code form it might look something like below. I added a range to the detection if you like, AND you might want to call the detect function with an onEnterFrame or or setInterval like evildog said instead of the onMouseMove because its not frequent enough to give an accurate response.

hope that helps

Walloompoom
Inspiring
July 12, 2006
How would you write the "Dont change" part?
Known Participant
July 12, 2006
The whole thing would be something like that. Makes sense?

// Variables that keep the mouse pos and if it was stopped already to avoid doing OnMouseStop all the time
// when the mouse doesn't move.
var xMousePos:Number = 0;
var yMousePos:Number = 0;
var bMouseIsStopped:Boolean = true;

function OnMouseStop()
{
// Your code here for when the mouse stops.
}

function onEnterFrame()
{
// Get the new mouse position.
var xNewMousePos:Number = _xmouse;
var yNewMousePos:Number = _ymouse;

// Check if the mouse has stopped if it wasn't stopped already.
if(!bMouseIsStopped && xNewMousePos == xMousePos && yNewMousePos == yMousePos)
{
bMouseIsStopped = true;
OnMouseStop();
}

// Keep the new mouse position.
xMousePos = _xNewMousePos;
yMousePos = _yNewMousePos;
}

mouseListener.onMouseMove = function() {
crosshair_mc._x = _xmouse;
crosshair_mc._y = _ymouse;
_root.mainMc.crosshair_mc.butterFlyMc.gotoAndStop("flap");

// The mouse isn't stopped anymore since it moved.
bMouseIsStopped = false;
};
Known Participant
July 12, 2006
Hey,

You can check the position of the mouse everyframe with a setInterval or onEnterFrame and keep that position in some variables, when both variables don't change, the mouse has stopped.