PDA

View Full Version : Cant't get simple mouse angle script to work...


johnnyboy
01-18-2006, 09:16 PM
Hi there,

I found a very simple script to detect the angle of the mouse:


onClipEvent (mouseMove) {

adjside =_root. _xmouse-_root.origin._x;
oppside = -1*(_root._ymouse-_root.origin._y);

angle = Math.atan2(oppside, adjside); // in radians
angle = Math.round(angle/Math.PI*180); // convert to degrees
_root.compass._rotation = -1*(angle);

}


Problem is, I want it to be a part of a function that I wrote, but it wont work... the angle variable comes out "NAN" instead of showing the angle...?


function setCursor (){
mouse_mc._x = _xmouse;
mouse_mc._y = _ymouse;
if (thePress == true) {
xdir = _xmouse; // activates the rotation via direction of mouse
//
adjside = _root._xmouse-_root.origin._x;
oppside = -1*(_root._ymouse-_root.origin._y);
angle = Math.atan2(oppside, adjside); // in radians
angle = Math.round(angle/Math.PI*180); // convert to degrees
_root.compass._rotation = -1*(angle);
}
updateAfterEvent ();
}


Any ideas here?

johnnyboy
01-19-2006, 01:39 PM
Found yet another cool script - (by Senocular)

But still want it to work as a part of a function, so it only counts when the mouse is down on a certain MC.

CD.getMouseRotation = function(){
var x = this._parent._xmouse-this._x;
var y = this._parent._ymouse-this._y;
return Math.atan2(y,x)*180/Math.PI;
};
CD.positionToMouse = function(){
this._lastrotation = this._rotation;
this._rotation = this.getMouseRotation() - this._clickrotation;
};
CD.onPress = function(){
this._clickrotation = this.getMouseRotation() - this._rotation;
this.onEnterFrame = this.positionToMouse;
};
CD.onRelease = CD.onReleaseOutside = function(){
delete this.onEnterFrame;
};

The idea is, that I want to split the stage up in a giant cheese with 40 slices (360 degrees/40) and when I move the mouse from slice to slice another function is called with a simple counter variable...

THE PROBLEM is, that I can't translate the scripts that I found to what I want it to do...

Please give me a hint in the right direction :)