Groups | Blog | Home
all groups > flash actionscript > july 2006 >

flash actionscript : Re: Mouse Stop


Walloompoom
7/12/2006 8:47:05 PM
Hi. I tried it but the cursor doesnt react at all. Here is the full code




// Variables that keep the mouse pos and if it was stopped already to avoid
doing OnMouseStop all the time
Mouse.hide();
// 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.
_root.mainMc.crosshair_mc.butterFlyMc.gotoAndStop("stop");
}
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();
trace ();
}
// 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");
updateAfterEvent();
// The mouse isn't stopped anymore since it moved.
bMouseIsStopped = false;
};
// When you click the mouse, check to see if the cursor is within the
boundaries of the Stage. If so, increment the number of shots.
mouseListener.onMouseDown = function() {
_root.mainMc.crosshair_mc.butterFlyMc.gotoAndStop("stop");
if (this.hitTest(_xmouse, _ymouse, false)) {
_global.shots++;
}
};
Mouse.addListener(mouseListener);
EvilDog2000
7/12/2006 9:07:29 PM
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.
Walloompoom
7/12/2006 9:22:02 PM
EvilDog2000
7/12/2006 9:42:31 PM
Did you put the trace right before the if condition?
if you did then trace everything independently until you find what's wrong

trace("Mouse stopped: " + bMouseIsStopped); // Should be false when the
mouse moves, true when it doesnt.
trace("New X Pos: " + xNewMousePos); // Should be the mouse position in X.
trace("New Y Pos: " + yNewMousePos); // Should be the mouse position in Y.
trace("Old X Pos: " + xMousePos); // Should be the previous mouse x
position from the last frame.
trace("Old Y Pos: " + yMousePos); // Should be the previous mouse y
position from the last frame.

it's called debugging my friend :)
AddThis Social Bookmark Button