Random movement

I just did the tutorial on random movement for flash mx, and it says how to specify the width and height, but what if i want to specify an area in the middle of the page, not just the whole page?

  1. You could simply put those objects inside a MovieClip and move it to the appropriate position.

  2. Replace the reset prototype with this code:
    [AS]// change these values
    var area = {xmin:40, xmax:100, ymin:40, ymax:100};
    MovieClip.prototype.reset = function() {
    var dist, norm;
    this.x = this._x;
    this.y = this._y;
    this.speed = Math.random()*4+2;
    this.targx = area.xmin+Math.random()*area.xmax-area.xmin;
    this.targy = area.ymin+Math.random()*area.ymax-area.ymin;
    dist = getdistance(this.x, this.y, this.targx, this.targy);
    norm = this.speed/dist;
    this.diffx = (this.targx-this.x)*norm;
    this.diffy = (this.targy-this.y)*norm;
    };[/AS]