# Drag – Limiting mc to be dragged horizontally or vertically

**URL:** <https://forum.kirupa.com/t/drag-limiting-mc-to-be-dragged-horizontally-or-vertically/314781>\
**Category:** flash\
**Created:** [October 8, 2010, 2:54pm UTC](https://forum.kirupa.com/t/drag-limiting-mc-to-be-dragged-horizontally-or-vertically/314781 "2010-10-08T14:54:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![neys](https://avatars.discourse-cdn.com/v4/letter/n/74df32/32.png) [@neys](https://forum.kirupa.com/u/neys)\
**Post date:** [October 8, 2010, 2:54pm UTC](https://forum.kirupa.com/t/drag-limiting-mc-to-be-dragged-horizontally-or-vertically/314781/1 "2010-10-08T14:54:18Z")

</div>

Hey guys, I the following problem which I hope you can answer, since the many hours I’ve spent googling it hasn’t helped out ☹

I got a movieclip which should be dragable horizontally and vertically, however it should be “locked” horizontally when dragging vertically as well as the other way around.

Here’s the following code I’m using to drag it horizontally:

```auto
[LEFT][COLOR=#993300]var[/COLOR] leftX:[COLOR=#993300]int[/COLOR] = [COLOR=#000000]0[/COLOR]; 
[COLOR=#993300]var[/COLOR] rightX:[COLOR=#993300]int[/COLOR] = [COLOR=#993300]stage[/COLOR].[COLOR=#000000]stageWidth[/COLOR]; 

my_mc.[COLOR=#000000]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000000]MOUSE_DOWN[/COLOR], onDown[COLOR=#000000])[/COLOR]; 
my_mc.[COLOR=#000000]addEventListener[/COLOR][COLOR=#000000]([/COLOR]MouseEvent.[COLOR=#000000]MOUSE_UP[/COLOR], onUp[COLOR=#000000])[/COLOR];  
[COLOR=#993300]
function[/COLOR] onDown[COLOR=#000000]([/COLOR][COLOR=#993300]e[/COLOR]:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#993300]

var[/COLOR] constrainY:Rectangle = [COLOR=#993300]new[/COLOR] Rectangle[COLOR=#000000]([/COLOR]leftX, [COLOR=#993300]e[/COLOR].[COLOR=#000000]currentTarget[/COLOR].[COLOR=#000000]y[/COLOR], rightX, [COLOR=#000000]0[/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#993300]

e[/COLOR].[COLOR=#000000]currentTarget[/COLOR].[COLOR=#993300]startDrag[/COLOR][COLOR=#000000]([/COLOR][COLOR=#993300]false[/COLOR], constrainY[COLOR=#000000])[/COLOR]; [COLOR=#000000]}[/COLOR] [COLOR=#993300]

function[/COLOR] onUp[COLOR=#000000]([/COLOR][COLOR=#993300]e[/COLOR]:MouseEvent[COLOR=#000000])[/COLOR]:[COLOR=#993300]void[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#993300]

e[/COLOR].[COLOR=#000000]currentTarget[/COLOR].[COLOR=#993300]stopDrag[/COLOR][COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]; [COLOR=#000000]
}
[/COLOR]
[/LEFT]

```

[COLOR=#000000]If I haven’t explained myself clear enough, I’m trying to create the effect that can be seen on [/COLOR][http://www.griplimited.com/](http://www.griplimited.com/)
