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:
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:
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:
Textfile name is: tx1/tx2/tx3
But when I assign a value to the textfield object like:
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.