# Dragging an MC?

**URL:** <https://forum.kirupa.com/t/dragging-an-mc/63501>\
**Category:** flash\
**Created:** [September 7, 2004, 12:47pm UTC](https://forum.kirupa.com/t/dragging-an-mc/63501 "2004-09-07T12:47:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![BUroKHUli](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/burokhuli/32/190_2.png) [@BUroKHUli](https://forum.kirupa.com/u/BUroKHUli)\
**Post date:** [September 7, 2004, 12:47pm UTC](https://forum.kirupa.com/t/dragging-an-mc/63501/1 "2004-09-07T12:47:38Z")

</div>

Hello,

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

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 🙂

---

<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 7, 2004, 1:15pm UTC](https://forum.kirupa.com/t/dragging-an-mc/63501/2 "2004-09-07T13:15:45Z")

</div>

Hello!

Check this functions in AS Dictionary

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

---

<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 7, 2004, 1:27pm UTC](https://forum.kirupa.com/t/dragging-an-mc/63501/3 "2004-09-07T13:27:08Z")

</div>

[http://www.kirupa.com/developer/flash5/dragmask.htm](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 🙂

---

<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 7, 2004, 1:31pm UTC](https://forum.kirupa.com/t/dragging-an-mc/63501/4 "2004-09-07T13:31:29Z")

</div>

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?

---

<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 7, 2004, 1:39pm UTC](https://forum.kirupa.com/t/dragging-an-mc/63501/5 "2004-09-07T13:39:40Z")

</div>

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…

---

<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 7, 2004, 1:42pm UTC](https://forum.kirupa.com/t/dragging-an-mc/63501/6 "2004-09-07T13:42:56Z")

</div>

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 🙂 Thanks shack 🙂 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.

---

<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 7, 2004, 3:19pm UTC](https://forum.kirupa.com/t/dragging-an-mc/63501/7 "2004-09-07T15:19:13Z")

</div>

```auto
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.

---

<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 8, 2004, 1:43am UTC](https://forum.kirupa.com/t/dragging-an-mc/63501/8 "2004-09-08T01:43:23Z")

</div>

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 ☹

---

<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 8, 2004, 10:07am UTC](https://forum.kirupa.com/t/dragging-an-mc/63501/9 "2004-09-08T10:07:02Z")

</div>

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

---

<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 8, 2004, 3:51pm UTC](https://forum.kirupa.com/t/dragging-an-mc/63501/10 "2004-09-08T15:51:40Z")

</div>

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.
