# Noob accessing different Classes with a variable question

**URL:** https://forum.kirupa.com/t/noob-accessing-different-classes-with-a-variable-question/314251
**Category:** flash
**Created:** [September 22, 2010, 8:13pm UTC](https://forum.kirupa.com/t/noob-accessing-different-classes-with-a-variable-question/314251 "2010-09-22T20:13:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Gilgemesh](https://avatars.discourse-cdn.com/v4/letter/g/dec6dc/32.png) [@Gilgemesh](https://forum.kirupa.com/u/Gilgemesh)
#### Post date: [September 22, 2010, 8:13pm UTC](https://forum.kirupa.com/t/noob-accessing-different-classes-with-a-variable-question/314251/1 "2010-09-22T20:13:48Z")

</div>

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:

```auto
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?

```auto
//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
