# Problem with Scrolling Mc by Mouse movement

**URL:** <https://forum.kirupa.com/t/problem-with-scrolling-mc-by-mouse-movement/280639>\
**Category:** Uncategorized\
**Created:** [January 29, 2009, 8:03pm UTC](https://forum.kirupa.com/t/problem-with-scrolling-mc-by-mouse-movement/280639 "2009-01-29T20:03:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![helious](https://avatars.discourse-cdn.com/v4/letter/h/b9e5f3/32.png) [@helious](https://forum.kirupa.com/u/helious)\
**Post date:** [January 29, 2009, 8:03pm UTC](https://forum.kirupa.com/t/problem-with-scrolling-mc-by-mouse-movement/280639/1 "2009-01-29T20:03:05Z")

</div>

Hello 🙂

Im using this piece of code in the Main stage, on the first frame, while my Mc is called bg\_mc.

```auto
this.onMouseMove = function() {
    constrainedMove(bg_mc, 4, 1);
};
function constrainedMove(target:MovieClip, speed:Number, dir:Number) {
    var mousePercent:Number = _xmouse/Stage.width;
    var mSpeed:Number;
    if (dir == 1) {
        mSpeed = mousePercent;
    } else {
        mSpeed = 1-mousePercent;
    }
    target.destX = Math.round(-((target._width-Stage.width)*mSpeed));
    target.onEnterFrame = function() {
        if (target._x == target.destX) {
            delete target.onEnterFrame;
        } else {
            target._x += Math.ceil((target.destX-target._x)*(speed/100));
        }
    };
}

```

BUT, it only works if the code is applied to the first frame on the main stage.  
How do i make an Mc, inside another MC (ex: Stage -\>Mc1-\>Mc2), scroll when i move the mouse? 🙂
