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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dragging Movie Clip With Easing Tween

Status
Not open for further replies.

nukecreative

Technical User
Oct 23, 2006
1
GB
Any assistance in this would be fantastic!

I've been going through the motions of trying to figure out the script involved in producing a draggable movie clip that eases out gradually once the mouse has been 'released'...

see example here -

i've tried using startDrag, onClipEvent etc etc with mx tween transitions but as i'm more of a designer than techy I must be getting things mixed up as i can't seem to get it right.

pleeeeease help me figure this one out!

many thanks
:)
 
I wrote an example script - hope you can get the basic idea from this. "mcX" is the MovieClip instance on Stage.
Code:
// AS2 main timeline
var isDrag:Boolean = false;
var lastX:Number = mcX._x;
var lastXMouse:Number = _xmouse;
var vector:Number = 0;
mcX.onPress = function():Void  {
	isDrag = true;
};
mcX.onRelease = mcX.onReleaseOutside=function ():Void {
	isDrag = false;
};
mcX.onEnterFrame = function():Void  {
	var thisX:Number = this._x;
	var thisXMouse:Number = _xmouse;
	if (thisXMouse != lastXMouse) {
		vector = thisX-lastX;
		if (isDrag) {
			this._x += thisXMouse-lastXMouse;
		}
	} else {
		this._x += vector;
		vector /= 1.05;
	}
	lastXMouse = thisXMouse;
	lastX = thisX;
};
stop();

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top