# Dynamically attaching components

**URL:** <https://forum.kirupa.com/t/dynamically-attaching-components/183891>\
**Category:** flash\
**Created:** [March 30, 2006, 11:33pm UTC](https://forum.kirupa.com/t/dynamically-attaching-components/183891 "2006-03-30T23:33:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yvillicana](https://avatars.discourse-cdn.com/v4/letter/y/46a35a/32.png) [@yvillicana](https://forum.kirupa.com/u/yvillicana)\
**Post date:** [March 30, 2006, 11:33pm UTC](https://forum.kirupa.com/t/dynamically-attaching-components/183891/1 "2006-03-30T23:33:25Z")

</div>

Hi,

Im trying to create a grid of textfields and dynamically attach a UIScrollBar component to each textfield. I cant seem to do it. Here is the code I have:

```auto

var gn:Number;
gn = 1;
for (c=1; c<9; c++) {
 for (i=1; i<9; i++) {
  px = 100*i;
  py = 40*c;
  _root.createTextField("grid"+gn, gn, px+i*10, py+200+c*10, 100, 40);
  with (_root["grid"+gn]) {
   multiline = true;
   wordWrap = true;
   border = true;
   autoSize = "true";
   type = "dynamic";
   font = "Arial";
   backgroundColor = 0xfff000;
   text = "yvette is trying to make this work but really doesnt know how to use components";
   background = "true";
  }
  initialization = {_targetInstanceName:"grid"+gn, horizontal:false};
  //your initialisation object
  _root.attachMovie('UIScrollBar', "myScrollbar"+gn, gn+65, initialization);
  //attach scrollbar
  _root["myScrollBar"+gn]._x = px;
  _root["myScrollBar"+gn].setSize(40);
  gn = gn+1;
 }
}

```

Where have I gone wrong?

Thanks,  
Yvette
