Creating movement with mouse cursor but with restrictions?


I have the following code which works fine but I would like to set a restriction on how far the movie will travel on it’s x and y axis so I can’t drag my movie out of the visible screen. How can this be achieved?

speed = .99; 
setInterval(CursorMovement, 40); 
function CursorMovement() { 
tvmovies._x = speed*(tvmovies._x-_xmouse)+_xmouse; 
tvmovies._y = speed*(tvmovies._y-_ymouse)+_ymouse;