Drag in circular motion

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:

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

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

Try this:

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

}

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;
}

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:

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)

thanks a lot senocular
thats what i wanted

Senocular, will you have my babies? :smiley:

senocular

would have your babbies if you werent a pimp.

Well Without a code overload how would you.

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

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

on a movieclip

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){

are you using or exporting to Flash 5?

Well Without a code overload how would you.

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

Did you see this:

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

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

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