View Full Version : dynamic text field question
Hi there.
Does anybody know if there is a way to do this without "if" and "for"
i have 20 text fields...
myTextField1
myTextField2
myTextField3
myTextField4
myTextField5
...
they all have the same name... only the number at the and changes.
Is there a way to do this...
myTextField[i].text = "blablabla";
so the variable i chages depending on a few checkboxes and depending on that, the text is written into different filds.
Thanx;)
ExNihilio
06-25-2009, 06:56 AM
yes there is
for(var i=1;i<21;i++){
myTextFieldParent["myTextField"+i].text="sdadsa";//if they have a parent
this["myTextField"+i].text="sdadsa";//if they re on stage by themselves
}
like this, note that myTextFieldParent is your text fields' parent, if they are not in a movieclip and just on the stage use this one
tadster
06-25-2009, 03:01 PM
or just :
for (var i:* = 0;i<=19;i++)
{TextField(this.getChildAt(i)).text = "words";}
//if they are the only children on the display
//or you can replace this with their parents name, if they are the only children inside
but you want to do it without a for loop? And you want i to change depending on checkboxes...
And i'm guessing that they would get different text not the same text?
so those checkboxes would get an event listener right?
And based on which check box is pressed, text gets written into the corresponding field?
so this could be the MouseEvent function of each check box :
function imclicked(e:MouseEvent):void
{
var thischeckbox:* = e.target.name.toString();
//each checkbox would be a sprite with a name like checkbox1
var numz:* = new RegExp("[0-9]{1,}", "g");
var boxnumber:* = Number(thischeckbox.match(numz).toString());
TextField(textboxholder.getChildAt(boxnumber - 1)).text = userinput;
//a textboxholder would be needed now to hold the TextFields
//and userinput would be the user input
}
hope this helps
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.