# Draggable movieclip - problem

**URL:** <https://forum.kirupa.com/t/draggable-movieclip-problem/242395>\
**Category:** Uncategorized\
**Created:** [October 25, 2007, 2:27pm UTC](https://forum.kirupa.com/t/draggable-movieclip-problem/242395 "2007-10-25T14:27:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt3](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/matt3/32/2096_2.png) [@matt3](https://forum.kirupa.com/u/matt3)\
**Post date:** [October 25, 2007, 2:27pm UTC](https://forum.kirupa.com/t/draggable-movieclip-problem/242395/1 "2007-10-25T14:27:28Z")

</div>

I’ve had a good hunt round but can’t find how I do this.

```auto
_root.box.ease = 2;
_root.box.targX = _root.myMC._x;
_root.box.targY = _root.myMC._y
_root.box.onPress = function() {
    this.drag = true;
};
_root.box.onEnterFrame = function() {
    if (this.drag == true) {
        this.targX = _root._xmouse;
        this.targY = _root._ymouse;
    }
    if (this._x != this.targX | this._y != this.targY) {
        this._x += (this.targX-this._x)/this.ease;
        this._y += (this.targY-this._y)/this.ease;
    }
};
_root.box.onMouseUp = function() {
    this.drag = false;
};

```

I’m using that code to drag my movie clip ‘box’ around with some easing to make it look a bit more fluid.

I used some code from here actually after alot of hunting around.

Now I want to ensure it doesn’t fly off the stage. How do I go about constraining it to the stage?

I’ve seen you can do something like…

```auto
[COLOR=#0066CC]on[/COLOR] [COLOR=#66CC66]([/COLOR]press[COLOR=#66CC66])[/COLOR] [COLOR=#66CC66]{[/COLOR]
        [COLOR=#0066CC]startDrag[/COLOR] [COLOR=#66CC66]([/COLOR][COLOR=#0066CC]this[/COLOR], [COLOR=#000000] **true** [/COLOR], [COLOR=#CC66CC]30[/COLOR], [COLOR=#CC66CC]80[/COLOR], [COLOR=#CC66CC]140[/COLOR], [COLOR=#CC66CC]110[/COLOR][COLOR=#66CC66])[/COLOR];
[COLOR=#66CC66]}[/COLOR]

```

But I can’t for the life of me figure out how to put that theory into the code above.

I’m not really an actionscript guru…well not an actionscript guru hehe more a cobbler together and mess around some so I’m scratching my head alot here.

Any help be grateful.

Cheers
