Preventing movie clip moving off frame

Hi I have a movieclip called soldierriver. Is can be moved around the stage by using the cursor keys. What I want is to prevent him from be moved off the stage. I know with drag and drop you use

But I don’t know how to add this into the code I am using for the cursor keys which is as follows.

onClipEvent(enterFrame) {
if (Key.isDown(Key.RIGHT)) {

if (Key.isDown(Key.LEFT)) {

if (Key.isDown(Key.UP)) {

if (Key.isDown(Key.DOWN)) {

Can someone please tell me how to include it in my code?