# Drag in circular motion

**URL:** <https://forum.kirupa.com/t/drag-in-circular-motion/26275>\
**Category:** Uncategorized\
**Created:** [July 21, 2003, 5:55pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275 "2003-07-21T17:55:53Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![cardjorg](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@cardjorg](https://forum.kirupa.com/u/cardjorg)\
**Post date:** [July 21, 2003, 5:55pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/1 "2003-07-21T17:55:53Z")

</div>

does any one know how to make something like the hand of a clock face draged in circular motion :

I tried

onClipEvent (enterFrame){  
this.\_rotation += this.\_xmouse ;  
}

and the hand goes all crazy when i move the mouse exept when i touch it  
and what i want is to be able to drag it to a number of the clock face .:+) :player: :cowboy: :thumb:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 21, 2003, 6:05pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/2 "2003-07-21T18:05:05Z")

</div>

i’m not sure, but maybe something like a motion guide?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 21, 2003, 6:12pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/3 "2003-07-21T18:12:14Z")

</div>

That won’t work because you are saying you want it to rotate @ whatever speed your coordinates are at. 🙂

Try this:

onClipEvent (enterFrame){  
this.\_rotation = \_root.\_xmouse;

}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 21, 2003, 6:30pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/4 "2003-07-21T18:30:43Z")

</div>

```auto
onClipEvent(load){
	// set a center point to rotate around
	this.center = {
		_x: 150,
		_y: 150
	}
	// the radius of the rotation around the center
	this.radius = 100;
	// a function to rotate the movieclip around the
	// center at the distance of the radius. x and y
	// values can be passed to point at, otherwise
	// the rotation goes to the mouse
	this.position = function(x,y){
		// assign x and y to the mouse locations if
		// they arent passed (x is undefined if not passed)
		if (x == undefined){
			x = this._parent._xmouse-this.center._x;
			y = this._parent._ymouse-this.center._y;
		}
		// develop an angle from x and y
		var angle = Math.atan2(y,x);
		// position the clip based on that angle (trig)
		this._x = this.center._x + Math.cos(angle)*this.radius;
		this._y = this.center._y + Math.sin(angle)*this.radius;
	}
	
	// start the movie off rotated to be straight up (y at -1)
	this.position(0,-1);
}
on(press){
	// when pressed, set the onMouseMove function to be position
	this.onMouseMove = this.position;
}
on(release, releaseOutside){
	// when you let go, delete the onMouseMove to prevent
	// further positioning
	delete this.onMouseMove;
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 21, 2003, 6:33pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/5 "2003-07-21T18:33:57Z")

</div>

thats for non rotational dragging in a circular path (movement involved) if you just want the rotation aspect, which the clock hand example would be, then youd reduce that above example into just this:

```auto
onClipEvent(load){
	this.position = function(x,y){
		// assign x and y to the mouse locations if
		// they arent passed (x is undefined if not passed)
		if (x == undefined){
			x = this._parent._xmouse-this._x;
			y = this._parent._ymouse-this._y;
		}
		// develop an angle from x and y
		var angle = Math.atan2(y,x);
		// assign rotation based on that angle converting it
		// from radians to degrees
		this._rotation = angle*180/Math.PI;
	}
	
	// start the movie off rotated to be straight up (y at -1)
	this.position(0,-1);
}
on(press){
	// when pressed, set the onMouseMove function to be position
	this.onMouseMove = this.position;
}
on(release, releaseOutside){
	// when you let go, delete the onMouseMove to prevent
	// further positioning
	delete this.onMouseMove;
}

```

(BTW 0 rotation assumes pointing to the right so when it rotates to the mouse, the direction facing to the right normally will point to the mouse)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 21, 2003, 6:38pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/6 "2003-07-21T18:38:05Z")

</div>

thanks a lot senocular  
thats what i wanted

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 21, 2003, 6:40pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/7 "2003-07-21T18:40:13Z")

</div>

Senocular, will you have my babies? 😃

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2003, 2:42pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/8 "2003-07-23T14:42:32Z")

</div>

senocular

would have your babbies if you werent a pimp.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 23, 2003, 2:44pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/9 "2003-07-23T14:44:23Z")

</div>

Well Without a code overload how would you.

make a bulet(Duplicated) Shoot out where ever your mouse location is.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 2:51pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/10 "2003-09-01T14:51:21Z")

</div>

Hey! I’m trying to use the AS Senocular did and I’m not getting any results. Where to I have to put the code? Is it a btn inside a mc? Or a mc inside a btn? Can u explain it for me, please? Thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 2:53pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/11 "2003-09-01T14:53:48Z")

</div>

on a movieclip

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 3:03pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/12 "2003-09-01T15:03:45Z")

</div>

This is what I get:

Scene=Scene 1, Layer=Layer 1, Frame=1: Line 19: Mouse events are permitted only for button instances  
on(press){

Scene=Scene 1, Layer=Layer 1, Frame=1: Line 23: Mouse events are permitted only for button instances  
on(release, releaseOutside){

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 3:09pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/13 "2003-09-01T15:09:37Z")

</div>

are you using or exporting to Flash 5?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 3:17pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/14 "2003-09-01T15:17:52Z")

</div>

> Well Without a code overload how would you.

make a bulet(Duplicated) Shoot out where ever your mouse location is.

Did you see this:

> **[kirupa.com - Game: How to Fire](https://www.kirupa.com/developer/mx/fire.htm)**
>
> Find out how to create flying bullets efficiently.

On the knob; Sen and I have some flas here:  
[http://www.kirupaforum.com/forums/showthread.php?s=&threadid=15211](http://www.kirupaforum.com/forums/showthread.php?s=&threadid=15211)  
(-:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 3:26pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/15 "2003-09-01T15:26:15Z")

</div>

Sen’s code work just fine. In Flash MX that is:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 1, 2003, 5:21pm UTC](https://forum.kirupa.com/t/drag-in-circular-motion/26275/16 "2003-09-01T17:21:19Z")

</div>

Yeh. I’m using Flash5!  
And cant use MX.  
☹
