PDA

View Full Version : Need to update a 'Spinning Wheel' script from AS 2.0 to AS 3.0.



Jashan
December 15th, 2008, 01:21 PM
Hey guys!

I need some help in transforming a script from AS 2.0 to AS 3.0. I'm busy for school making some small game in which I use a spinning wheel. I really like this script, only it's written in AS 2.0. Can anyone help me transform this into AS 3.0? I'd really appreciate it!





damp = .96; //friction
r = 0; //rotation
accr = 0; //speed of rotation

knob.onPress = function() {
dragging = true;
//find mouse y coordinate in relation to knob origin
a = _root._ymouse - knob._y;
//find mouse x coordinate in relation to knob origin
b = _root._xmouse - knob._x;
//using arctangent find the spot of rotation (in degrees)
oldr = Math.atan2(a,b)*180/Math.PI;
}

knob.onRelease = knob.onReleaseOutside = function() {
dragging = false;
}

knob.onEnterFrame = function() {
if (dragging) {
//find mouse y coordinate in relation to knob origin
a = _root._ymouse-knob._y;
//find mouse x coordinate in relation to knob origin
b = _root._xmouse-knob._x;
//using arctangent find the spot of rotation (in degrees)
r = Math.atan2(a,b)*180/Math.PI;

//use current rotation and previous rotation
//to find acceleration
//averages the acceleration with the
//previous acceleration for smoother spins
accr = ((r - oldr) + accr)/2;
//apply the acceleration to the rotation
knob._rotation += accr;
//remember current rotation as old rotation
oldr = r;
feedbacka.text = a;
feedbackb.text = b;
}
else {
knob._rotation += accr;
//apply friction to acceleration force
//and if acceleration gets tiny, just set it to zero
if (Math.pow(accr, 2) > .0001 ) {
accr *= damp;
}
else{
accr = 0;
}
}
//spit out feedback continuosly
feedbackr.text = knob._rotation;
feedbackaccr.text = accr;
}

Jashan
December 15th, 2008, 03:42 PM
Anyone?

Sage_of_Fire
December 15th, 2008, 05:11 PM
It would be much easier to read and test if you wrap your code in as BB code tags like this:


[ as ]
// AS3 code goes here
[ /as ]

Just take out the spaces between [, as, and ], and your code will be formatted and easy to read. The numbering means that nobody can test it out without getting rid of the numbers first.

For help with the actual code, I think you should look in the Adobe AS3 Reference (http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/) for the Event class. AS3 has a totally new way of handling user interaction, and you need to learn it to use AS3. Don't worry, it's very easy and logical; you should be able to fix your script quickly.