I know this has been brought up before but mine’s different.
I have some script to drag along a circle (listed below) but here’s the catch: I dont want to use angles to calculate the position. I want there to be multiple objects (balls in this case) and I want the Y position of the clicked ball to BE the Y position of the mouse, then the X position gets calculated on the circle. This way now, if you have your mouse out in the far right corner of the screen, the ball is not all the way up the circle. I want it to match the mouse so that I can achieve a straight-line drag but with an x-position in the circle Thanks.
var rX:Number = 150;
var rY:Number = 300;
var numItems:Number = 12;
var zeroSector:Object = sector(0, rX, rY);
function sector(degree:Number, radiusX:Number, radiusY:Number):Object {
// coordinates of a point on ellipse
var xpos:Number = radiusX * Math.cos(degree * Math.PI / 180);
var ypos:Number = radiusY * Math.sin(degree * Math.PI / 180);
// find the angle that has the Y-coords of the mouse position, solve for angle somehow...
return {x:xpos, y:ypos};
}
function objPosition():Void { // detecting coordinates of a clip
var ratio:Number = rX / rY;
var anAngle = Math.atan2(this._parent._xmouse, this._parent._ymouse);
var deg:Number = 90-(Math.atan2(Math.sin(anAngle), Math.cos(anAngle) * ratio)) * (180 / Math.PI);
var _sector:Object = sector(deg, rX, rY);
this._x = _sector.x;
this._y = _sector.y;
//this._y = this._parent._ymouse;
}
// draw ellipse
this.createEmptyMovieClip("mc", 0);
mc._x =-90;
mc._y = 300;
this.mc.lineStyle(0, 0xAAAAAA);
this.mc.moveTo(zeroSector.x, zeroSector.y);
for (d = 0; d <= 360; d += 5) {
var _sector:Object = sector(d, rX, rY);
this.mc.lineTo(_sector.x, _sector.y);
}
// create draggalbe clip
mc.createEmptyMovieClip("drag_mc", 0);
mc.drag_mc.lineStyle(50, 0x002277, 100);
mc.drag_mc.lineTo(0, 1);
mc.drag_mc._x = zeroSector.x;
mc.drag_mc._y = zeroSector.y;
mc.drag_mc.onPress = function():Void {
this.onMouseMove = objPosition;
this.onRelease = this.onReleaseOutside = function ():Void {
delete this.onRelease;
delete this.onReleaseOutside;
delete this.onMouseMove;
};
};