I am trying to write some code that will pull a different instance of a library item into a placeholder on the stage depending on what button is pressed. Here is the code I have right now, but it seems like there should be a better way of doing this:
switch (swatchesChoice) {
case "whiteBrick" :
var choice2:whiteBrick = new whiteBrick();
contentBox.addChild(choice2);
break;
case "tanBrick" :
var choice2:tanBrick = new tanBrick();
contentBox.addChild(choice2);
break;
case "oldBrick" :
var choice3:oldBrick = new oldBrick();
contentBox.addChild(choice3);
break;
}
Here is how I think it should work, but I get an error saying the class isn’t a compile-time constant. Is this possible to simplify for reuse?
//setup the variable to hold my class info
var test:Class;
//set the correct class for the variable based on
//which item has been selected
switch (swatchesChoice) {
case "whiteBrick" :
test = whiteBrick;
break;
case "tanBrick" :
test = tanBrick();
break;
case "oldBrick" :
test = oldBrick();
break;
}
//then place the correct library item into
//placeholder on the stage
var choice:test = new test();
contentBox.addChild(choice);
Any help would be greatly appreciated.
-Gil