Restricting my game character's movement

I have made a simple game with a scuba diver that has to avoid oncoming sharks and would like help on 2 things please.

  1. How do I prevent my scuba diver from leaving the screen? As when i hold either up, down, left or right long enough he will leave the stage entirely.

  2. How can I make my sharks enter the screen at random rather than having them enter from the same position each time?

Any help will be greatly appreciated - Here is my code:

(FOR MY SCUBA)

onClipEvent (load) {
xspeed = 10;
yspeed = 10;
}

onClipEvent (enterFrame) {

if (Key.isDown(Key.RIGHT)) {
    _x += xspeed;

}
if (Key.isDown(Key.LEFT)) {
    _x -= xspeed;

}
if (Key.isDown(Key.UP)) {
    _y -= yspeed;

}
if (Key.isDown(Key.DOWN)) {
    _y += yspeed;    
}

}

(AND FOR MY SHARK)

onClipEvent (load) {
lw = -150;
xspeed =8;
}
onClipEvent (enterFrame) {
if (this.hitTest(_root.scuba)) {
_root.gotoAndPlay(3)
//_root.health.play()
//_x = 1200;
//_y = random(100)+200;
}

_x -= xspeed;

if (_x<lw) {
    _x = 1000;
    //_y = random(0)+400;
    //xspeed = random(4)+1;
}

}