# Restrict \_xmouse and \_ymouse to box

**URL:** <https://forum.kirupa.com/t/restrict--xmouse-and--ymouse-to-box/4866>\
**Category:** Uncategorized\
**Created:** [August 23, 2002, 6:56am UTC](https://forum.kirupa.com/t/restrict--xmouse-and--ymouse-to-box/4866 "2002-08-23T06:56:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian\_monkey](https://avatars.discourse-cdn.com/v4/letter/b/c4cdca/32.png) [@brian\_monkey](https://forum.kirupa.com/u/brian_monkey)\
**Post date:** [August 23, 2002, 6:56am UTC](https://forum.kirupa.com/t/restrict--xmouse-and--ymouse-to-box/4866/1 "2002-08-23T06:56:45Z")

</div>

Hi. I am making a menu with 5 pictures in one movie clip and I have a mc of a line ( all on frame 1) and it’s code is:  
onClipEvent (enterFrame) {  
with (\_root.menu) {  
diff = (this.\_x-\_root.\_xmouse)/10;  
\_root.menu.\_x = \_root.menu.\_x +diff;  
}  
}

but I want to make another movie clip in the shape of a rectangle and I want the menu only to slide if the mouse position changes in the rectangle. so I don’t want the picture mc to move if the mouse isn’t changing positions in the rectangle; it should just stay put. please help me boyies. thanks \_root.brian

---

<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:** [August 23, 2002, 7:28am UTC](https://forum.kirupa.com/t/restrict--xmouse-and--ymouse-to-box/4866/2 "2002-08-23T07:28:09Z")

</div>

well… if the rectangle is a movieclip with an instance name you could do something like this.

```auto

onClipEvent (enterFrame) {
    if(_root._xmouse>_root.square._x&&_root._xmouse<_root.square._x+_root.square._width&&_root._ymouse>_root.square._y&&_root._ymouse<_root.square._y+_root.square._height){
        with (_root.menu) {
            diff = (this._x-_root._xmouse)/10;
            _root.menu._x = _root.menu._x +diff;
        }
    }
}

```

provided the square movie clip had an instance name of square and it was located on the main timeline.

---

<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:** [August 23, 2002, 2:24pm UTC](https://forum.kirupa.com/t/restrict--xmouse-and--ymouse-to-box/4866/3 "2002-08-23T14:24:35Z")

</div>

as an alternative to David’s, check out the scriptable masks tutorial

[http://www.kirupa.com/developer/actionscript/scriptable\_masks.asp](http://www.kirupa.com/developer/actionscript/scriptable_masks.asp)

in there, check out the explanation on getBounds. Go to the part that says “Almost Done”

---

<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:** [August 24, 2002, 1:11am UTC](https://forum.kirupa.com/t/restrict--xmouse-and--ymouse-to-box/4866/4 "2002-08-24T01:11:28Z")

</div>

thanks David. I can only get the menu to go to the left though.  
either way I move the mouse it goes to the left and the speed is not consistent to the speed the mouse moves. please help a boy once more. thanks a bunch - brazil
