# Adding MovieClip's to the stage

**URL:** <https://forum.kirupa.com/t/adding-movieclips-to-the-stage/261233>\
**Category:** flash\
**Created:** [May 24, 2008, 5:21pm UTC](https://forum.kirupa.com/t/adding-movieclips-to-the-stage/261233 "2008-05-24T17:21:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregmax](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@gregmax](https://forum.kirupa.com/u/gregmax)\
**Post date:** [May 24, 2008, 5:21pm UTC](https://forum.kirupa.com/t/adding-movieclips-to-the-stage/261233/1 "2008-05-24T17:21:11Z")

</div>

This is what I am trying to do:

[AS]  
var level = new “level\_” + hero.lvl;  
[/AS]

I remember similar methods of this worked for AS2 (when creating a class/instance), but with the whole new re-written language of AS3, I am not able to do so. I am trying to add a movie clip to the stage depending on the heros current level.

Can someone quickly please tell me of a workaround or solution to this. Thank you in advance (I pulled chunks of hairs out of my head already, haha)

---

<div class="post-metadata">

**Author:** ![McGuffin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mcguffin/32/408_2.png) [@McGuffin](https://forum.kirupa.com/u/McGuffin)\
**Post date:** [May 24, 2008, 5:41pm UTC](https://forum.kirupa.com/t/adding-movieclips-to-the-stage/261233/2 "2008-05-24T17:41:59Z")

</div>

```auto

import flash.utils.getDefinitionByName;

var classObj:Class= getDefinitionByName("level_" + hero.lvl);
var level:* = new classObj();

```

---

<div class="post-metadata">

**Author:** ![gregmax](https://avatars.discourse-cdn.com/v4/letter/g/ac8455/32.png) [@gregmax](https://forum.kirupa.com/u/gregmax)\
**Post date:** [May 24, 2008, 6:04pm UTC](https://forum.kirupa.com/t/adding-movieclips-to-the-stage/261233/3 "2008-05-24T18:04:45Z")

</div>

Thanks McGuffin!

It didn’t work the first time for me though… I looked at a sample script from the Actionscript 3 docs (I didn’t know of the getDefinitionClassByName() function just til you mentioned it) and tried this way instead:

[AS]  
import flash.utils.getDefinitionByName;

var class\_obj:Class = getDefinitionByName(“Level\_” + hero.lvl) as Class;  
var lvl:MovieClip = new class\_obj();

[/AS]

Then it worked. I guess adding “as Class” made that big of a difference. Thanks again

---

<div class="post-metadata">

**Author:** ![McGuffin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mcguffin/32/408_2.png) [@McGuffin](https://forum.kirupa.com/u/McGuffin)\
**Post date:** [May 24, 2008, 6:16pm UTC](https://forum.kirupa.com/t/adding-movieclips-to-the-stage/261233/4 "2008-05-24T18:16:57Z")

</div>

Ah, forgot that, my apologies. Just so you know, you can also typecast like:

```auto

var class_obj:Class = Class(getDefinitionByName("Level_" + hero.lvl));

```

There are benefits to using this against “as”, and “as” over this method. Searching “typecasting actionscript 3” and you’ll turn up some good articles.
