Functions

Hi
Im kind of new to writing funtions.
I have written a bit of code that randomly shifts a movie clip about when a button is pressed. I then copy and pasted the same code lots of times to make lots of different movie clips move when the same button is pressed.

This is very well but lots of copy and pasting this aint good practice there must be a better way of doing this so I thought about how to write a function to do the same job.

here is the code I have written

function startpos(){
_root.pic1_mc._x = 85;
_root.pic1_mc._y = 10;
pic1_mc.xpos = 0;
pic1_mc.ypos = 0;
x_array = new Array();
y_array = new Array();
}

function movepos(){
pic1_mc.xpos += (Math.floor(Math.random()*3)-1);
pic1_mc.ypos += (Math.floor(Math.random()*3)-1);
pic1_mc._x += pic1_mc.xpos;
pic1_mc._y += pic1_mc.ypos;
x_array[0] = pic1_mc._x;
y_array[0] = pic1_mc._y;
x_array.push(pic1_mc._x);
y_array.push(pic1_mc._x);
if (y_array[10]) {
delete this.onEnterFrame;
}
}

this.press_mc.onMouseDown = function() {
startpos();

onEnterFrame = function() {

movepos(pic1_mc);
};

It works however I am know stuck with making the code flexibble ie so I can attatch the function to lots of diferent clips
Any ideas

cheers