PDA

View Full Version : Targeting a Textfield Created with Array



Pherank
November 18th, 2009, 09:24 PM
I need to be able to set a property of the 3rd textfield created within this for loop:



for (var i:int = 0; i < menuArray.length; i++) {
menuText = new TextField;
menuText.name = "navBttn_" + i;
menuText.x = xCoord;
menuText.y = (i * 20) + yCoord;
//
menuText.text = menuArray[i];
//
addChild(menuText);
//
menuText.addEventListener(MouseEvent.ROLL_OVER, MainRollOver);
menuText.addEventListener(MouseEvent.ROLL_OUT, MainRollOut);
menuText.addEventListener(MouseEvent.CLICK, onMainSelectItem);

}
//Change property of 3rd textfield here


What's the best way to target that object?

creatify
November 18th, 2009, 10:07 PM
this["navBttn_2"].text = "whatever";

TheCanadian
November 18th, 2009, 11:00 PM
Actually it'd be: (getChildByName("navBttn_2") as TextField).text = "whatever";

Pherank
November 18th, 2009, 11:02 PM
Thanks, but one of the thing I need to do is set mouseEnabled to false, so if I use the following code


this["navBttn_2"].mouseEnabled = false;

I get this error:
TypeError: Error #1010: A term is undefined and has no properties.

TheCanadian
November 18th, 2009, 11:05 PM
Please see my post above :)

Pherank
November 18th, 2009, 11:16 PM
Yes! Thanks TheCanadian - I knew it probably needed "as TextField" specified, but I wasn't sure about the rest of the syntax.

TheCanadian
November 18th, 2009, 11:29 PM
You're welcome :hoser: