# Mouse mc boundaries

**URL:** <https://forum.kirupa.com/t/mouse-mc-boundaries/184253>\
**Category:** programming\
**Created:** [April 3, 2006, 7:39pm UTC](https://forum.kirupa.com/t/mouse-mc-boundaries/184253 "2006-04-03T19:39:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kpxnamja](https://avatars.discourse-cdn.com/v4/letter/k/7c8e57/32.png) [@kpxnamja](https://forum.kirupa.com/u/kpxnamja)\
**Post date:** [April 3, 2006, 7:39pm UTC](https://forum.kirupa.com/t/mouse-mc-boundaries/184253/1 "2006-04-03T19:39:12Z")

</div>

Hello, how are all of you guys doing?  
Well here’s my problem:  
I’m trying to “limit”or create a boundary for my mc that is being controlled by the influence of the mouse. here is the source:

```php
/ **********************************************************
    Hero Fish
    Movement AI.
********************************************************** /
onClipEvent (load) {
mousefollow = function () {
        myRadians = Math.atan2(_root._ymouse-this._y, _root._xmouse-this._x);
        myDegrees = Math.round((myRadians*180/Math.PI));
        _root.yChange = Math.round(_root._ymouse-this._y);
        _root.xChange = Math.round(_root._xmouse-this._x);
        if(_root.moveAllow == false)
        {
            _root.xChange = 0
            _root.yChange = 0
        }
        _root.yMove = Math.round(_root.yChange/_root.speed);
        _root.xMove = Math.round(_root.xChange/_root.speed);

        this._y += _root.yMove;
        this._x += _root.xMove;
        this._rotation = myDegrees+90;
};
}

onClipEvent (enterFrame) {
    mousefollow();
}

```

(Slightly modified from [Actionscript.org](http://Actionscript.org) tutorials.)

When I test my .swf it works ok because when the mouse is out of the .swf box the mc can no longer pass the boundary, but when I make my application full screen the mc follows my mouse past the given boundary.  
see below pictures.

So I wanted to limit the mc, but at the same time allow it to follow my mouse, while the mouse is outside the box.

![](http://forum.kirupa.com/uploads/kirupa/2342/de0eff2be6b9c381.jpg)  
Good MC, stay inside that little box sucker!!!

![](http://forum.kirupa.com/uploads/kirupa/2343/c56ee02a938ba7cf.jpg)  
Bad mc… stay in that boundary!!!

So I’m open to any suggestion…

Here’s some of my hypothesis… So I don’t act like a actionscript freeloader…

I could use an if statement?  
I could create a square, boundary mc labeled boundary, and if hit test is true, move it back? , but having the chance of being stuck…

I’m clueless…
