Boundary

hey guys im trying to make a little birds eye view game but i cant seem to get a bounary on the border to work to stop my character walking off the stage…

this is the codee i am using how can i put a boundary into it?

onClipEvent (enterFrame) {

if (Key.isDown(Key.UP)){
speed += 1;
gotoAndStop (2)
} else {
gotoAndStop (1)
speed = 0}

if (Key.isDown(Key.DOWN)) {
speed -= 0;
}
if (Math.abs(speed)>8) {
speed *= .8;
}
if (Key.isDown(Key.LEFT)) {
_rotation -= 10;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 10;
}

// This will make the car move
speed = .98;
x = Math.sin(_rotation
(Math.PI/180))speed;
y = Math.cos(_rotation
(Math.PI/180))speed-1;
if (!_root.wall.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
speed *= -.8;
}
}