# Drag "inside"

**URL:** <https://forum.kirupa.com/t/drag-inside/34966>\
**Category:** Uncategorized\
**Created:** [November 8, 2003, 3:51pm UTC](https://forum.kirupa.com/t/drag-inside/34966 "2003-11-08T15:51:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerry](https://avatars.discourse-cdn.com/v4/letter/j/5daacb/32.png) [@jerry](https://forum.kirupa.com/u/jerry)\
**Post date:** [November 8, 2003, 3:51pm UTC](https://forum.kirupa.com/t/drag-inside/34966/1 "2003-11-08T15:51:48Z")

</div>

Simple question coming up…

See attached .fla - how can I make the draggable MC ONLY draggable inside the “drag area” - so that it dossent’ cross the border of the “drag area”…?

Any help would be NICE!

---

<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:** [November 8, 2003, 4:24pm UTC](https://forum.kirupa.com/t/drag-inside/34966/2 "2003-11-08T16:24:51Z")

</div>

Delete any code you have now, and place this code on the timeline containing the two movieclips. Then, give the box to be dragged the instance name ‘dragb’ and the area to drag in ‘darea’

```auto

MovieClip.prototype.keepInsideOf = function (boundary) {
	if (this._x-this._width/2<boundary._x-boundary._width/2) {
		this._x = boundary._x-boundary._width/2+this._width/2;
	}
	if (this._x+this._width/2>boundary._x+boundary._width/2) {
		this._x = boundary._x+boundary._width/2-this._width/2;
	}
	if (this._y-this._height/2<boundary._y-boundary._height/2) {
		this._y = boundary._y-boundary._height/2+this._height/2;
	}
	if (this._y+this._height/2>boundary._y+boundary._height/2) {
		this._y = boundary._y+boundary._height/2-this._height/2;
	}
};
dragb.onPress = function() {
	this.onMouseMove = function() {
		this._x = _root._xmouse;
		this._y = _root._ymouse;
		this.keepInsideOf(darea)
	};
};
dragb.onRelease = dragb.onReleaseOutside=function () {
	delete this.onMouseMove;
};

```

---

<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:** [November 8, 2003, 4:27pm UTC](https://forum.kirupa.com/t/drag-inside/34966/3 "2003-11-08T16:27:30Z")

</div>

That is some nice coding dude - once again THX alot! 🙂

---

<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:** [November 8, 2003, 4:32pm UTC](https://forum.kirupa.com/t/drag-inside/34966/4 "2003-11-08T16:32:13Z")

</div>

Can that you made jerry be used as masking any text added ? Some thing I would like to to try.

Regards Barrie.

---

<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:** [November 8, 2003, 4:36pm UTC](https://forum.kirupa.com/t/drag-inside/34966/5 "2003-11-08T16:36:20Z")

</div>

It probably can. You need an example ?

---

<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:** [November 8, 2003, 4:39pm UTC](https://forum.kirupa.com/t/drag-inside/34966/6 "2003-11-08T16:39:09Z")

</div>

Please Voetsjoeba I have seen it on some sites just dont know how to do it yet,

Regards Barrie.

---

<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:** [November 8, 2003, 4:58pm UTC](https://forum.kirupa.com/t/drag-inside/34966/7 "2003-11-08T16:58:02Z")

</div>

Here’s an example:

---

<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:** [November 8, 2003, 5:52pm UTC](https://forum.kirupa.com/t/drag-inside/34966/8 "2003-11-08T17:52:34Z")

</div>

Thankyou Voetsjoeba, I see you removed the grey box Jerry did! or did you? I was kinda thinking the grey box would be covering or uncovering the text, I will master that masking soon as I worked out how you did it 🙂 Nice work.

Regards Barrie
