Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

possible to restict startDrag to a path? 1

Status
Not open for further replies.

firegambler

Technical User
Sep 25, 2002
455
AT
Hi out there!
Is it possible to make an object movable by a startDrag() function and restrict the movements to a certain path (maybe a line shaped like a wave or something) or is there some sophisticated way to get the same result?
look at these files;

the scrollbar looks pretty funny but the way it is done terrifies me a little. there must be some easier way around this... any suggestions?

thanks in advance

regards

tektips.gif
 
just an idea but how about using the shape that you want to constrict the drag to (maybe invisible) and then do a hittest on that.
 
You could map out a path mathematically and then position an object along it according to mouse position but you're restricted to a set of path shapes wheich can be described by a formula.

Other than that you could create an array which carries a set of values for _x position and use the mouse _y position as an index to that array.

Hmmm...

 
Here's one that keeps a clip restricted to a sine wave with the horizontal position lined up to the mouse when you press the mouse (you'll need a clip on the stage with instance name 'ball'):

Code:
//variables
_global.scaleFactor = 100;
//functions
convert = function (val) {
	// convert degrees to radians
	return val/180*Math.PI;
};
trackMouse = function () {
	// get mouse position - then track along a sine wave
	var x = _xmouse;
	newX = convert(x);
	y = Math.sin(newX)*scaleFactor;
	ball._x = x;
	ball._y = y;
};
//call functions on drag
this.onMouseDown = function() {
	this.onEnterFrame = trackMouse;
};
this.onMouseUp = function() {
	this.onEnterFrame = null;
};
 
quick google search came up with this script for dragging in a circle

onClipEvent (load) {
xbar = this._x;
ybar = this._y;
}
onClipEvent (mouseDown) {
mdown=true;
}
onClipEvent (mouseUp) {
mdown=false;
}
onClipEvent (enterFrame) {
if (mdown) {
this._rotation =
(Math.atan(((_root._xmouse-xbar))/((-_root._ymouse+ybar))))*360/2/Math.PI;
}
}

 
thanks guys i'll try to play around with this a little :)

regards

tektips.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top