Simplifying my code

Alright,

Here’s just the begining of my huge function that runs through and create a textfield on the stage, according to a counter… I’m stuck with this huge function that goes through the steps to create the same thing 10 times (i.e. textBox1, textBox2, textBox3, etc). How can I turn this into one function or class (i don’t know if i need to use an array in here) so that I don’t have to do this for each text box… i need to be able to delete any of the text boxes and update the function as well.

I hope im making myself clear… Thank you so much

createTextBox = function () {
 // grab the x,y of mouse and assign text box dimensions
 tBoxX = _xmouse;
 tBoxY = _ymouse;
 tBoxW = 100;
 tBoxH = 20;
 // textCount
 textBoxCount++;
 // check textBoxCount
 if (textBoxCount eq 11) {
  trace("you've exeeded your text box ammount");
  textBoxCount = 10;
 } else {
  // create text box
  if (textBoxCount eq 1) {
   _root.createTextField("textBox"+String(textBoxCount), textBoxCount, tBoxX, tBoxY, tBoxW, tBoxH);
   _root.tBoxX1 = textBox1._x;
   _root.tBoxY1 = textBox1._y;
   trace("textBox"+String(textBoxCount));
   _root.textBox1.type = "input";
   _root.textBox1.border = true;
   _root.textBox1.borderColor = 0xFF0000;
   _root.textBox1.multiline = true;
   _root.textBox1.wordWrap = true;
   _root.textBox1.setFocus(true);
   _root.resizeText_btn1._x = tBoxX+tBoxW;
   _root.resizeText_btn1._y = tBoxY+tBoxH;
   _root.textBox1.onSetFocus = function(oldFocus) {
    _root.mouseNum = 1;
    this.borderColor = 0xFF0000;
   };
   _root.textBox1.onKillFocus = function(newFocus) {
    this.borderColor = 0xCCCCCC;
   };

…the else continues for textBox2