Random movement within irregular boundaries

hi all,

i’m hoping that someone can help me out here.

attached is an .fla file that has a number of movieclips that move around at random, this part works great. but the movement is only applicable to a rectangle/uniformed area - defined in the action script on frame 1.

function getdistance (x, y, x1, y1) {    var run, rise;    run = x1-x;    rise = y1-y;    return (hyp(run, rise));}function hyp (a, b) {    return (Math.sqrt(a*a+b*b));}MovieClip.prototype.reset = function () { var dist, norm, movie_height, movie_width;

//   movie_height: refers to the height of your movie//   movie_width: refers to the width of your movie
//--------------------------------------------
movie_height = 150;movie_width = 300;
//--------------------------------------------

speed = Math.random()*4+2;targx = Math.random()*(movie_width-_width);targy = Math.random()*(movie_height-_height);dist = _root.getdistance(_x, _y, targx, targy);
norm = speed/dist;diffx = (targx-_x)*norm;diffy = (targy-_y)*norm;};

MovieClip.prototype.move = function () { var cycle;


// cycle: specifies speed of the movement. The smaller //         number, the faster the objects move.
//--------------------------------------------
cycle = 200;
//--------------------------------------------
if (_root.getdistance(_x, _y, targx, targy)>speed) {x += diffx;y += diffy;} else {x = targx;y = targy;if (!this.t) {t = getTimer();}if (getTimer()-t>cycle) {reset();t = 0;}}_x = x;_y = y;}

and each clip that moves randomly has this script applied…

onClipEvent (enterFrame) {    move();}

what i want the clips to do is move around within the area of the big mc named “area” in the middle of the stage - by which i mean move anywhere within the boundaries of the shape of the “area” but never outside.

i remember i did something similar many many moons ago - but can’t find any reference/files/scripting for what it was that i did to make it work. not sure if the phrase “shape flag” is something that is on the right lines? it was so long ago!

does anyone know what i need to add/edit/change in the AS shown above to achieve the desired effect please?

be really grateful for any pointer, tips or help that anyone feels generous to offer me :wink:

fingers crossed…