# Adding max values for movement

**URL:** <https://forum.kirupa.com/t/adding-max-values-for-movement/188721>\
**Category:** flash\
**Created:** [May 10, 2006, 10:55am UTC](https://forum.kirupa.com/t/adding-max-values-for-movement/188721 "2006-05-10T10:55:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![exit](https://avatars.discourse-cdn.com/v4/letter/e/e19adc/32.png) [@exit](https://forum.kirupa.com/u/exit)\
**Post date:** [May 10, 2006, 10:55am UTC](https://forum.kirupa.com/t/adding-max-values-for-movement/188721/1 "2006-05-10T10:55:38Z")

</div>

I am putting together a game where you fly a plane by pressing the arrow keys.

They acritionscript below handles that nicely. But I want to add boundaries  
so the plane will stay on the stage and not fly off it…

But I haven’t been able to accomplish without bringing the plane movement to a complete stop.

I am hoping to get help adding the [COLOR=#ff0000]**xposmax = 500 [COLOR=black]&[/COLOR] yposmax = 300** [/COLOR][COLOR=black]to my actionscript. So the plane will stay inbetwenn x (0-500) and y (0-300).[/COLOR]

Hoping someone has a suggestion?? :beam:

gravity = 0.1;  
fall = 0.1;  
xpos = 0;  
\*\*[COLOR=red]xposmax = 500;  
[/COLOR]\*\*ypos = 0;  
[COLOR=red] **yposmax = 300;** [/COLOR]

\_root.onEnterFrame = function() {  
if (Key.isDown(Key.LEFT)) {  
xpos = xpos-1;  
} else if (Key.isDown(Key.RIGHT)) {  
xpos = xpos+1;  
}  
if (Key.isDown(Key.UP)) {  
up = true;  
fall = fall-0.9;  
gravity = 0.3;  
} else {  
up = false;  
}  
plane.\_y = plane.\_y+fall;  
plane.\_x = plane.\_x+xpos;  
gravity = gravity\*1.04;  
fall = fall+gravity;  
}
