Frame 1
function distanceBetween(x1, y1, x2, y2) {
var x = (x2 - x1);
var y = (y2 - y1);
return(Math.sqrt((x * x) + (y * y)));
}
function onEnterFrame() {
var oldX = ball_mc._x;
var oldY = ball_mc._y;
xv = xv * friction;
yv = yv * friction;
yv = yv + gravity;
ball_mc._x = ball_mc._x + xv;
ball_mc._y = ball_mc._y + yv;
var dist = distanceBetween(_xmouse, _ymouse, ball_mc._x, ball_mc._y);
var angleTo = Math.atan2(ball_mc._y - _ymouse, ball_mc._x - _xmouse);
ball_mc._x = (Math.cos(angleTo) * Math.min(stringLength, dist)) + _xmouse;
ball_mc._y = (Math.sin(angleTo) * Math.min(stringLength, dist)) + _ymouse;
xv = ball_mc._x - oldX;
yv = ball_mc._y - oldY;
string_mc._x = _xmouse;
string_mc._y = _ymouse;
string_mc._rotation = ((angleTo / Math.PI) * 180) - 90;
string_mc._yscale = Math.min(stringLength, dist);
string_mc._xscale = stringLength - string_mc._yscale;
}
xv = 0;
yv = 0;
friction = 0.99;
gravity = 5;
stringLength = 200;
ball_mc._color = new Color(ball_mc);
ball_mc._color.setTransform({ra:100, ga:0, ba:0});
ball_mc.onPress = function () {
this._color.setTransform({ra:Math.random() * 100, ga:Math.random() * 100, ba:Math.random() * 100});
};