Dragging an MC?

Hello,

It’s been a while since I have visited this site. I would like to say “HI” to all the Flash Helpers around :slight_smile: Now, I’m back again with a few questions about How To’s in Flash :slight_smile:

Problem:

I wanted to make an MC that can be dragged only from LEFT to RIGHT with a little ease on it. I was trying to look for some tutorials in this site but unfortunately wasn’t able to find one close to what I had in mind.

Thank You :slight_smile:

Hello!

Check this functions in AS Dictionary

myMC.stopDrag();
myMC.startDrag();

http://www.kirupa.com/developer/flash5/dragmask.htm

something like this link above but only it is only draggable on the X Axis and not the Y. And with a little of easing when you release the Mouse.

I hope you know what I mean? I could have explained it in a better way :slight_smile:

btek : coooooooll!! I made my first DRAG AS.

on (press) {
drag.startDrag(“true”);
}

on (release) {
drag.stopDrag();
}

How do you lock it on the X axis only and with a little easing on release?

there are other parameters to startDrag, that “draws” a box where you can move around the movieclip, check out those, I don’t have flash here at the moment…

I think so far this is my first complex AS ever since I learned how to use _root and _parent. LOL

I’ll try to figure this one out, but I hope you would help me with what I realy wanted :slight_smile: Thanks shack :slight_smile: I’ll keep this thread alive for future reference.

Problem:
My MC has 400pix in width, I want that when dragged, it will not go off the stage with is also 400pix wide.

slideX = function () {
	if (0<_root._xmouse) {
		if (_root._xmouse < 400) {
			myMC._x = _root._xmouse;
		} else {
			myMC._x = 400;
		}
	} else {
		myMC._x = 0;
	}
};
myMC.onPress = function() {
	startSlide = setInterval(slideX, 10);
};

myMC.onRelease = myMC.onReleaseOutside = function() {
	clearInterval(startSlide);
}

Assuming that you have a MC named myMC and that you don’t want it to slide more than 400px or less than 0px on the X (relative to the Stage’s X).

You can add easing and such, and you’ll probably need to change the instance name of the movie clip and whatever bounds you want set, but I think that should help you on your way.

I used a setInterval just because startDrag did not offer enough flexibility. You can change the setInterval interval timing also, if you don’t want to burn CPU power (though it’s not exactly CPU-intensive sliding a MC along the X with a few if-then’s tossed in).

You might also play around with registration points to get the true slide bounds you’re going for.

Hello KENNY, I tried to use your AS. Got weird results. Here, im attaching the file.

  1. Everytime I attempted to drag my MC, it would jump, something like that. I tried to play around with the REGISTRY POINT and yet came up with no solution.

  2. I didn’t figure out how to add easing on it :frowning:

The sliding is very nice for me already. I just want to ask why whenever you click on the MOVIE CLIP, it would jump to the CENTER MC with regards to it’s Registry Point then start to drag. Anyway of fixing this?

Thanks

Calculate the difference between xmouse and your MC’s X. Then add/subtract from your MC’s X depending on the value of the difference between your MC’s X and xmouse.