# Mouse mc boundaries

**URL:** <https://forum.kirupa.com/t/mouse-mc-boundaries/184304>\
**Category:** Uncategorized\
**Created:** [April 4, 2006, 5:23am UTC](https://forum.kirupa.com/t/mouse-mc-boundaries/184304 "2006-04-04T05:23:28Z")\
**Posts on this page:** 3\
**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 4, 2006, 5:23am UTC](https://forum.kirupa.com/t/mouse-mc-boundaries/184304/1 "2006-04-04T05:23:28Z")

</div>

Hello, _[SIZE=2]I do realize that I have already posted this at the AS section, but I felt that there was no response going to be made, and besides this is considered more a game than an AS problem… :nose:  
[/SIZE]_  
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 Code:
 		 		[LEFT] [COLOR=#000000] [COLOR=#ff8000]/ **********************************************************
Hero Fish
Movement AI.

```

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
[/COLOR][COLOR=#0000bb]onClipEvent [/COLOR]COLOR=#007700 {  
[/COLOR][COLOR=#0000bb]mousefollow [/COLOR][COLOR=#007700]= function () {  
[/COLOR][COLOR=#0000bb]myRadians [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]Math[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]atan2[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]\_root[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]\_ymouse[/COLOR][COLOR=#007700]-[/COLOR][COLOR=#0000bb]this[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]\_y[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]\_root[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]\_xmouse[/COLOR][COLOR=#007700]-[/COLOR][COLOR=#0000bb]this[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]\_x[/COLOR][COLOR=#007700]);  
[/COLOR][COLOR=#0000bb]myDegrees [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]Math[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]round[/COLOR]COLOR=#007700;  
[/COLOR][COLOR=#0000bb]\_root[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]yChange [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]Math[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]round[/COLOR]COLOR=#007700;  
[/COLOR][COLOR=#0000bb]\_root[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]xChange [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]Math[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]round[/COLOR]COLOR=#007700;  
if([/COLOR][COLOR=#0000bb]\_root[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]moveAllow [/COLOR][COLOR=#007700]== [/COLOR][COLOR=#0000bb]false[/COLOR][COLOR=#007700])  
{  
[/COLOR][COLOR=#0000bb]\_root[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]xChange [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]0  
\_root[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]yChange [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]0  
[/COLOR][COLOR=#007700]}  
[/COLOR][COLOR=#0000bb]\_root[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]yMove [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]Math[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]round[/COLOR]COLOR=#007700;  
[/COLOR][COLOR=#0000bb]\_root[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]xMove [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]Math[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]round[/COLOR]COLOR=#007700;

```
    [/COLOR][COLOR=#0000bb]this[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]_y [/COLOR][COLOR=#007700]+= [/COLOR][COLOR=#0000bb]_root[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]yMove[/COLOR][COLOR=#007700];
    [/COLOR][COLOR=#0000bb]this[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]_x [/COLOR][COLOR=#007700]+= [/COLOR][COLOR=#0000bb]_root[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]xMove[/COLOR][COLOR=#007700];
    [/COLOR][COLOR=#0000bb]this[/COLOR][COLOR=#007700].[/COLOR][COLOR=#0000bb]_rotation [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]myDegrees[/COLOR][COLOR=#007700]+[/COLOR][COLOR=#0000bb]90[/COLOR][COLOR=#007700];

```

};  
}

[/COLOR][COLOR=#0000bb]onClipEvent [/COLOR]COLOR=#007700 {  
[/COLOR][COLOR=#0000bb]mousefollow[/COLOR]COLOR=#007700;  
}  
[/COLOR] [/COLOR] [/LEFT]

(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…

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 4, 2006, 6:21am UTC](https://forum.kirupa.com/t/mouse-mc-boundaries/184304/2 "2006-04-04T06:21:15Z")

</div>

Something along these lines?

C:-)

---

<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 4, 2006, 7:32am UTC](https://forum.kirupa.com/t/mouse-mc-boundaries/184304/3 "2006-04-04T07:32:10Z")

</div>

ah that is wonderful 😃 thanks
