-
dynamic variables
I have a class that is used to create buttons (sprites). I need to be able to create x amount of them. I tried to use a for loop to do that.
for (var a:int = 0; a<=subtopics_number;a++){
var test:SubTopicButton = new SubTopicButton(a);
addChild(test);
}
That creates the buttons but my problem is in how to refrence them from any later point. something like removeChild(x)...
is there a way to do something like: (i know these down work but just examples of what i'd like to be able to do )
var test[i]:SubTopicButton = new SubTopicButton(a);
var test + i:SubTopicButton = new SubTopicButton(a);
basically create dynamic variable names so that i can use them later.
If theres a diffrent way to do this and im totally missing it let me know. If this needs to be move over to the flash newb section thats ok also.
Thanks for help.
-
Use setChildIndex(test, a);
-
ex1
Code:
for (var a : uint = 0; a < subtopics_number; a++) {
var test : SubTopicButton = new SubTopicButton (a);
test.name = "test" + a;
addChild(test);
}
removeChild (getChildByName ("test1"));
ex2
Code:
var subTopicButtons : Object = new Object ();
for (var a : uint = 0; a < subtopics_number; a++){
var test : SubTopicButton = new SubTopicButton(a);
subTopicButtons["test" + a] = test;
addChild(test);
}
removeChild (subTopicButtons["test1"]);
-