-
Spinning wheel via mouse drag rotation
I have researched all over and have found some that "kind of" work, but the coding always has issues with CS3 (my version). I am more proficient in AS2, but would be willing to try AS3 if that is the way to go.
I need a script that will allow the user to use their mouse to drag a wheel that will slow down to a stop. Think "Wheel of Fortune" style. Where it stops will trigger an event.
Any help will be greatly appreciated...I am pulling my hair out over this one!
-
Hello! Interesting issue...!
This might come close to what you are looking for (haven't tested it yet):
var diffY:Number=0;
var diffX:Number=0;
var speed:Number=0;
var desacceleration:Number = 0.95;
onEnterFrame = function(){
wheel_mc.onPress = function(){
var oldX: Number = _xmouse;
var oldY: Number = _ymouse;
}
wheel_mc.onRelease = function(){
var newX: Number = _xmouse;
var newY: Number = _ymouse;
defineMySpin();
}
(speed<1? speed=0:speed*=desacceleration);
wheel_mc._rotation += speed;
}
function defineMySpin():Void{
diffY = newY-oldY;
diffX = newX-oldX;
speed = Math.sqrt(diffX*diffX + diffY*diffY);
}
Hope it works o
It might not work if the user starts dragging too far a distance etc...
Cheers!
-
Thanks for replying! I just tried your code, but doesn't seem to work for me.
I did find one that sort of works. The spinning works, but I am trying to figure out how to have the wheel trigger an action depending on where the wheel lands. (a section of the wheel). I threw in a hitTest code, but it isn't working when the wheel STOPS, just constantly during the spinning. Here is the code I'm using:
Code:
onClipEvent (load) {
wx = getProperty("", _x);
wy = getProperty("", _y);
Mouse = "up";
}
onClipEvent (mouseUp) {
Mouse = "up";
../rotater:go = "yes";
../rotater:w = w;
}
onClipEvent (mouseDown) {
../rotater:go = no;
Mouse = "down";
current_rotation = getProperty("", _rotation);
if (mouse eq "down") {
mx = getProperty("_level0", _xmouse);
my = getProperty("_level0", _ymouse);
slope = (my-wy)/(mx-wx);
theta = Math.atan(slope)*(180/Math.PI);
if (mx>wx and my<wy) {
ang = current_rotation-theta;
} else if (mx<wx and my<wy) {
ang = current_rotation-(180-theta)*-1;
} else if (mx<wx and my>wy) {
ang = current_rotation-180+theta;
} else if (mx>wx and my>wy) {
ang = current_rotation-(360-theta)*-1;
}
_level0:theta = theta;
_level0:ang = ang;
}
}
onClipEvent (mouseMove) {
if (mouse eq "down") {
rot2 = rot1;
rot1 = getProperty("", _rotation);
w = (rot1-rot2)*5;
mx = getProperty("_level0", _xmouse);
my = getProperty("_level0", _ymouse);
slope = (my-wy)/(mx-wx);
theta = Math.atan(slope)*(180/Math.PI);
if (mx>wx and my<wy) {
setProperty("", _rotation, theta+ang);
} else if (mx<wx and my<wy) {
setProperty("", _rotation, (180-theta)*-1+ang);
} else if (mx<wx and my>wy) {
setProperty("", _rotation, 180+theta+ang);
} else if (mx>wx and my>wy) {
setProperty("", _rotation, (360-theta)*-1+ang);
}
setProperty("", _xscale, 100);
setProperty("", _yscale, 100);
_level0:theta = theta;
_level0:ang = ang;
}
}
onClipEvent (mouseMove) {
updateAfterEvent();
if (rotation<=0) {
rotation = 0;
_root.clicker.gotoAndStop(1);
if (_root.clicker.hitTest(_root.wheel.pies.p1)) {
trace("Picked Category 1");
} else if (_root.clicker.hitTest(_root.wheel.pies.p2)) {
trace("Picked Category 2");
} else if (_root.clicker.hitTest(_root.wheel.pies.p3)) {
trace("Picked Category 3");
}
}
}
Any more help would be appreciated!
-
you should only do the hittest when the wheel is nog spinning. the variable names are not very clear, but i'm guessing you should put the hittest inside an if(rot2==rot1) or whatever defines if the wheel is spinning.
good luck on that.
-
Just my 2 cents, but some of that (very old) code wont work if you publish AS2 or above player 5 or 6, at least. I suggest you convert all the Flash4 syntax to a more recent/current way of coding. Some expressions are deprecated and will NOT work. For instance:
../rotater:w = w; <- Flash4 way of coding variables.
should be
_parent.rotator.w = w;
if (mouse eq "down") <- Flash4 operator
should be
if(mouse=="down")
etc.
Finally make sure ALL the variables are declared if you publish above player 6.
gparis
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|