Keeping Randomly Placed Objects Within The Stage

Hello,

I am placing 10 movie clips randomly within the stage using this simple script:

 
for(i=0; i<10; i++) {
 var t = this.attachMovie("imgs","imgs"+i,i);
 t.cacheAsBitmap = true;
 t._x = Stage.width*Math.random(550);
 t._y = Stage.height*Math.random(450);
 t.onRollOver = function(){
  this.swapDepths(this._parent.getNextHighestDepth());
 }
}

What I am trying to figure out is how to keep all the objects contained within the stage bondaries. Right now some of them are going off screen when they are placed, and this looks goofy when placed in the HTML page I am creating.

Any ideas on keeping them contained in an area so the edges are all within said area?

thanks,
jsm_

Assuming the registration point for “imgs” is set to the upper-right corner:

 t._x = (Stage.width-t._width)*Math.random(Stage.width);
 t._y = (Stage.height-t._height)*Math.random(Stage.width);

Works perfect, and so simple… should have figured that out.

Thanks again.