If statements

Hi,

im trying to get a mc that is in side another mc to stay in the stage boundry with if statements

here is my code

onClipEvent (enterFrame)
{
this.onEnterFrame = function()

{
var x = 0
var y = 0
if (this._x < x)
{
this._x = this._x+50;
}
if (this._y < y)
{
this._y = this._y+50;
}
}
}

all this does is move the mc over to the left 50 px and down 50 px weather it is out side of the stage or with in the stage

the parentmc is loaded dynamicly then placed in several postions, some are in the middle of the stage and dont need moved

some are close to the edge of the stage and are being cut off

what am i doing wrong

any help showing the error of my ways are much help

thank you