Hi there,
I’ve created a loop that will create dynamic textfields by using the information from an array.
This is how I did it:
var bigWordsArray:Array=['Services','creative content','previous clients'];
var myTextField:TextField = new TextField();
var myFormat:TextFormat = new TextFormat();
for (var i:int = 0; i < bigWordsArray.length; i++) {
trace (bigWordsArray*);
myTextField = new TextField();
addChild(myTextField);
myTextField.text = bigWordsArray*;
//myTextField.x = 200*i;
myTextField.y = 40*i;
myTextField.selectable = false;
myTextField.background = true;
myTextField.autoSize = TextFieldAutoSize.LEFT;
myFormat = new TextFormat();
myFormat.size = 24;
myTextField.setTextFormat(myFormat);
}
Now I want to be able to make each textfield interactive (a button). But I have no idea how identify them within this loop. How can I apply an instance name to each textfield?
I **thought **I had to use something similar to this:
var btn:MovieClip=bigWordsArray["btn"+i];
btn.addEventListener(MouseEvent.CLICK, onButtonClick);
btn.buttonMode=true;
btn.mouseChildren=false;
btn.id=i;
function onButtonClick(e:MouseEvent):void {
trace ("Do something");
}
I wish I understood AS3 more!
Thanks
Mark