
Код:
this.follow = function () {
var dx:Number = this._xmouse - this.clip._x;
var dy:Number = this._ymouse - this.clip._y;
var angle1:Number = Math.atan2 (dy, dx) * (180 / Math.PI);
var angle2:Number = this.clip._rotation;
if (angle2 < 0) {
angle2 += 360;
}
if (angle1 < 0) {
angle1 += 360;
}
var a:Number = angle2 - angle1;
if (a > 180) {
a -= 360;
} else if (a < -180) {
a += 360;
}
a *= this.speed;
if (Math.abs (a) > 0.01) {
this.clip._rotation -= a;
} else {
this.clip._rotation = angle1;
delete this.onEnterFrame;
}
};
this.onMouseMove = function () {
//// mc - имя клипа который крутится за курсором
this.clip = mc;
//// скорость поворота, значения:
//// [speed = 0] - вращение без задержки
//// [0 < speed < 1] - чем меньше, тем плавнее поворот
//// [speed = 1] - вращение без задержки
this.speed = 0;
this.onEnterFrame = follow;
};