Help with code - arrays

Hi all! I hope you can help me with this one:

I’ve got a button called “btn1”. On release it moves a movie clip “sub1”. I’ve got another movie clip called “tail” which is always glued to the end of “sub1” and follows its movement. The function that moves “sub1” and glues “tail” to “sub1” looks like this (thanks to rhamej and scotty - I’ve found it in their very helpful post):

MovieClip.prototype.moveIt = function () {
	this.onEnterFrame = function () {
		this._x += (stopX-this._x)/speed;
		if (this._x>stopX) {
			this._x = stopX;
		}
		tail._x = sub1._x + sub1._width;
	};
};

The code for pressing the button looks like this:

btn1.onRelease = function() {
		sub1.moveIt();
}

So what movie clip the “tail” follows is defined when I create the function. (Works very nicely.)
But let’s say I’ve got many “sub” movie clips: “sub1”, “sub2”, “sub3”, … , “sub20” and many buttons that move the subs: “btn1”, “btn2”, …, “btn20”.
“btn1” moves “sub1”, “btn2” moves “sub2” and so on. It wouldn’t be very practical to create new functions for each movement of subs and following of the “tail”, specially since the subs will get upgraded a lot. It would be smart to create an array for the subs and the buttons, so the “tail” would follow the right sub depending on the button pressed.

I’m really a begginer and I’m still trying to understand and read the code. Could you please help me write the function that would allow that?

Thank you,
Petra