# Circular movement along path?

## Recommended Posts

Hi.

I found this script (se below) that I need for moving an object attached to a eliptical path.

The scrip itself works ok. But what I love to do is to add some smooth tween when mouse is stopped.

Or even better have a greensock soulotion for a carousel tweening

Maybe with combination of beizer and dynamicProps?

I did read about the circle2D class some. But This needs to be As2 because it targets flashplayer8 at minimum.

I would offcourse consider a Club memberhip if ther is a way with As2

Regards

Olle

```var rX:Number = 200;// radius1
var rY:Number = 100;// radius2
var ang:Number = 10; // angle to rotate ellipse
//
var zeroSector:Object = sector(0, rX, rY, ang);

// coordinates of a point on ellipse
var cx:Number = radiusX * Math.cos(degree * Math.PI / 180);
var cy:Number = radiusY * Math.sin(degree * Math.PI / 180);
// rotation of system of coordinates
var xx:Number = cx * Math.cos(angle * Math.PI / 180) - cy * Math.sin(angle * Math.PI / 180);
var yy:Number = cx * Math.sin(angle * Math.PI / 180) + cy * Math.cos(angle * Math.PI / 180);
return {x:xx, y:yy};
}

function objPosition():Void { // detecting coordinates of a clip
var ratio:Number = rX / rY;

var anAngle = Math.atan2(this._parent._xmouse, this._parent._ymouse) + ang * Math.PI / 180;
var deg:Number = 90-(Math.atan2(Math.sin(anAngle), Math.cos(anAngle) * ratio)) * (180 / Math.PI);

var _sector:Object = sector(deg, rX, rY, ang);
this._x = _sector.x;
this._y = _sector.y;
}
// draw ellipse
this.createEmptyMovieClip("mc", 0);
mc._x = Stage.width / 2;
mc._y = Stage.height / 2;
this.mc.lineStyle(0, 0xDDDDDD);
this.mc.moveTo(zeroSector.x, zeroSector.y);
for (d = 0; d <= 360; d += 5) {
var _sector:Object = sector(d, rX, rY, ang);
this.mc.lineTo(_sector.x, _sector.y);
}
// create draggalbe clip
mc.createEmptyMovieClip("drag_mc", 0);
mc.drag_mc.lineStyle(50, 0x007722, 100);
mc.drag_mc.lineTo(0, 1);
mc.drag_mc._x = zeroSector.x;
mc.drag_mc._y = zeroSector.y;

mc.drag_mc.onMouseMove = function():Void  {
this.onMouseMove = objPosition;
this.onRelease = this.onReleaseOutside = function ():Void {
delete this.onRelease;
delete this.onReleaseOutside;
delete this.onMouseMove;
};
};
```

##### Share on other sites

The CirclePath2D class would give you a lot of flexibility and would likely perform better too. But you're right - it's only AS3. However, you're welcome to port it to AS2 if you want. shouldn't be horribly difficult unless you're not familiar with AS3 at all. I'd offer to port it myself, but I've got too much on my plate at the moment to take the time.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account