# Referencing variable in addChild

**URL:** <https://forum.kirupa.com/t/referencing-variable-in-addchild/306473>\
**Category:** flash\
**Created:** [March 16, 2010, 8:31am UTC](https://forum.kirupa.com/t/referencing-variable-in-addchild/306473 "2010-03-16T08:31:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![carrot](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@carrot](https://forum.kirupa.com/u/carrot)\
**Post date:** [March 16, 2010, 8:31am UTC](https://forum.kirupa.com/t/referencing-variable-in-addchild/306473/1 "2010-03-16T08:31:27Z")

</div>

First off I want to say that the resources on this site have been excellent, thanks.

Does anyone know how to reference a variable when adding a new Movieclip?

Currently I am using this method:

```auto
var myVariable:String = "one"
 
if(myVariable == "one"){
    var myMovieClip = this.addChild(new one())
}
else if(myVariable == "two"){
    var myMovieClip = this.addChild(new two())
}
else if(myVariable == "three"){
    var myMovieClip = this.addChild(new three())
}

```

etcetera.

I was wondering if there was a way to just have it put the variable in to the addChild argument, meaning I could do away with all the ifs to check what the variable is.

e.g.

```auto
var myVariable:String = "one"
var myMovieClip = this.addChild(new >>whatever myVariable is<<())

```

I tried doing a search, but had no idea what to search for, so I didn’t find anything.
