Adding max values for movement

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;
}