Hello, everybody! I’m new here and pretty much ‘rediscovering’ ActionScript and I wanted to know if any of you wonderful, talented guys out there (grins) could help me out with this bit of code that has been driving me mad for the past 5 hours…
Ok, I have a movieclip with some animation on my main timeline, and a knob movieclip. I want the user to control the reproduction/timeline of the animation by pressing and rotating the mouse over the knob: if the direction is clockwise, the animation plays forward, if the direction is counter clockwise, the animation goes backwards.
Anyways. So far, so good. By doing a LOT of research I managed to come up with this piece of code that does exactly that. But… I wanted to know if it was possible (I mean, I know it must be, I’m just at my wit’s end and honestly brained-out with this) to add some sort of physics to the rotation of the knob… I mean, I want the user to have a more ‘realistic’ experience when they turn the knob, like the knob having some friction or maybe it not just stopping when they stop rotating the mouse, but it rather having some drag/easing/whatever… you know the drill
So, this is my code… Please, forgive me if it’s sloppy or not the way it should be… I would truly appreciate it if you could also give me some pointers to make it more up to standards… Thank you so much in advance!! And chocolate chip cookies for everyone who wants to help!
movie_mc.[COLOR=#993300]stop[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
body_mc.[COLOR=#993300]onPress[/COLOR] = [COLOR=#993300]function[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
pressing = [COLOR=#993300]true[/COLOR];
[COLOR=#993300]var[/COLOR] prevAngle = [COLOR=#000000]0[/COLOR];
body_mc.[COLOR=#000000]point_mc[/COLOR].[COLOR=#993300]onMouseMove[/COLOR] = [COLOR=#993300]function[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
x = body_mc.[COLOR=#000000]point_mc[/COLOR].[COLOR=#993300]_xmouse[/COLOR];
y = body_mc.[COLOR=#000000]point_mc[/COLOR].[COLOR=#993300]_ymouse[/COLOR]*-[COLOR=#000000]1[/COLOR];
angle = [COLOR=#993300]Math[/COLOR].[COLOR=#993300]atan[/COLOR][COLOR=#000000]([/COLOR]y/x[COLOR=#000000])[/COLOR]/[COLOR=#000000]([/COLOR][COLOR=#993300]Math[/COLOR].[COLOR=#993300]PI[/COLOR]/[COLOR=#000000]180[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#993300]if[/COLOR] [COLOR=#000000]([/COLOR]x<[COLOR=#000000]0[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
angle += [COLOR=#000000]180[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]if[/COLOR] [COLOR=#000000]([/COLOR]x>=[COLOR=#000000]0[/COLOR] && y<[COLOR=#000000]0[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
angle += [COLOR=#000000]360[/COLOR];
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#993300]_root[/COLOR].[COLOR=#000000]body_mc[/COLOR].[COLOR=#000000]knob_mc[/COLOR].[COLOR=#993300]onEnterFrame[/COLOR] = [COLOR=#993300]function[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]if[/COLOR] [COLOR=#000000]([/COLOR]pressing[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]_root[/COLOR].[COLOR=#000000]body_mc[/COLOR].[COLOR=#000000]knob_mc[/COLOR].[COLOR=#993300]_rotation[/COLOR] = [COLOR=#000000]([/COLOR]angle*-[COLOR=#000000]1[/COLOR][COLOR=#000000])[/COLOR] + [COLOR=#000000]90[/COLOR];
[COLOR=#993300]var[/COLOR] newRot = [COLOR=#993300]_root[/COLOR].[COLOR=#000000]body_mc[/COLOR].[COLOR=#000000]knob_mc[/COLOR].[COLOR=#993300]_rotation[/COLOR];
[COLOR=#993300]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#993300]Math[/COLOR].[COLOR=#993300]abs[/COLOR][COLOR=#000000]([/COLOR][COLOR=#993300]Math[/COLOR].[COLOR=#993300]ceil[/COLOR][COLOR=#000000]([/COLOR]newRot-prevAngle[COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR]>[COLOR=#000000]1[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#000000]([/COLOR]newRot-prevAngle[COLOR=#000000])[/COLOR]>[COLOR=#000000]1[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]_root[/COLOR].[COLOR=#000000]movie_mc[/COLOR].[COLOR=#993300]nextFrame[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR] [COLOR=#993300]else[/COLOR] [COLOR=#000000]{[/COLOR]
[COLOR=#993300]_root[/COLOR].[COLOR=#000000]movie_mc[/COLOR].[COLOR=#993300]prevFrame[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]
prevAngle = newRot;
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
[COLOR=#000000]}[/COLOR]
body_mc.[COLOR=#993300]onRelease[/COLOR] = body_mc.[COLOR=#993300]onReleaseOutside[/COLOR] = [COLOR=#993300]function[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
pressing = [COLOR=#993300]false[/COLOR];
[COLOR=#000000]}[/COLOR]