# How to Access Dynamically Generated Textfield.text in a Class

**URL:** <https://forum.kirupa.com/t/how-to-access-dynamically-generated-textfield-text-in-a-class/318160>\
**Category:** flash\
**Created:** [January 12, 2011, 1:10am UTC](https://forum.kirupa.com/t/how-to-access-dynamically-generated-textfield-text-in-a-class/318160 "2011-01-12T01:10:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zik80](https://avatars.discourse-cdn.com/v4/letter/z/c37758/32.png) [@zik80](https://forum.kirupa.com/u/zik80)\
**Post date:** [January 12, 2011, 1:10am UTC](https://forum.kirupa.com/t/how-to-access-dynamically-generated-textfield-text-in-a-class/318160/1 "2011-01-12T01:10:59Z")

</div>

I am having trouble referencing dynamically generated textfield in a document class. I gives me the assigned name when traced, but generates an error when I refer to the name. Here are the documents:

**THE TextField Class:**

```auto
package{
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFieldType;
    import flash.events.MouseEvent;

    public function MyText(){
[INDENT] public class MyText extends Sprite{
	for (var i = 0; i<4; i++) {
		var mc = createTextField();
		mc.name = "tx"+i;
		addChild(mc);
		mc.addEventListener(MouseEvent.MOUSE_OVER,traceName);
		
		addChild(txl);
	}

        function createTextField() {
	       var tx = new TextField();
	       tx.width =100;
	       tx.height =30;
	       tx.background = true;
	       tx.border = true;
	       tx.type = TextFieldType.DYNAMIC;
	       return tx;
        }

	function traceName(e:MouseEvent):void {
		trace("Textfile name is: " + e.target.name);
	}[/INDENT]
          [COLOR="Blue"]}[/COLOR]
    [COLOR="Blue"]}[/COLOR]
}

```

**The Main Class:**

```auto
package{
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFieldType;
    import flash.events.MouseEvent;

    public function Main(){
    public class Main extends Sprite{
    .......

       var myText:MyText=new MyText();
       stage.addChild(myText);
    }
}

```

Here is the problem: when I mouse over any of the textfield, it correctly trace this:

```auto
Textfile name is: tx1/tx2/tx3

```

But when I assign a value to the textfield object like:

```auto
myText.tx1.text="Testing";

```

I get an error instead of the replacement. This doesn’t happen if I created the textfields manually. Help is appreciated.
