Hi all,
I have the problem that i want a square to have an angular movement when i
drag it.
I have found a script that comes very close to it but the angualr movement
only apears when releasing the clip.
I tried hard to get it working the way i want it but I fail. =(
I'm more a designer than a coder so i hope someone here could give me an
advice or tip how i can do this.
Or maybe a link to a tutorial covering this topic?
That's the script:
Thank you very much
damp = .8;
bar.onPress = function() {
bar.onEnterFrame = undefined;
bar.vr = 0;
bar.vx = 0;
bar.vy = 0;
downX = _xmouse;
downY = _ymouse;
onEnterFrame = makeVector;
};
bar.onRelease = bar.onReleaseOutside=function () {
findVector();
bar.onEnterFrame = barMove;
onEnterFrame = undefined;
clear();
};
function makeVector() {
clear();
lineStyle(1, 0, 100);
moveTo(downX, downY);
lineTo(_xmouse, _ymouse);
dx = _xmouse-downX;
dy = _ymouse-downY;
}
function findVector() {
vectorAngle = Math.atan2(dy, dx);
vectorMag = Math.sqrt(dx*dx+dy*dy);
vectorX = downX-bar._x;
vectorY = downY-bar._y;
vectorDist = Math.sqrt(vectorX*vectorX+vectorY*vectorY);
barAngle = Math.atan2(vectorY, vectorX);
resultAngle = vectorAngle-barAngle;
bar.vr = Math.sin(resultAngle)*vectorMag*vectorDist/65;
bar.vx += dx*.5;
bar.vy += dy*.5;
}
function barMove() {
this.vx *= damp;
this.vy *= damp;
this.vr *= damp;
this._x += this.vx;
this._y += this.vy;
this._rotation += this.vr;
bounds = this.getBounds(_root);
if (bounds.xMin<20) {
this._x += 20-bounds.xMin;
this.vx *= -1;
} else if (bounds.xMax>520) {
this._x += 520-bounds.xMax;
this.vx *= -1;
}
if (bounds.yMin<20) {
this._y += 20-bounds.yMin;
this.vy *= -1;
} else if (bounds.yMax>380) {
this._y += 380-bounds.yMax;
this.vy *= -1;
}
}