# AS3 addChild when what you're adding is dynamic?

**URL:** <https://forum.kirupa.com/t/as3-addchild-when-what-youre-adding-is-dynamic/251267>\
**Category:** flash\
**Created:** [February 6, 2008, 6:59pm UTC](https://forum.kirupa.com/t/as3-addchild-when-what-youre-adding-is-dynamic/251267 "2008-02-06T18:59:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stickeroo](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@Stickeroo](https://forum.kirupa.com/u/Stickeroo)\
**Post date:** [February 6, 2008, 6:59pm UTC](https://forum.kirupa.com/t/as3-addchild-when-what-youre-adding-is-dynamic/251267/1 "2008-02-06T18:59:23Z")

</div>

I don’t even think I worded the title correctly, but here’s what I’m running into:

I have an XML file that contains, among other things, a node called \<image\> which contains a string that refers to the relevant Library asset.

(I changed the linkage base class to flash.display.Sprite).

Now, when the user does whatever that gets them to a point where I need to load the image referenced in the \<img\> node…how do I do it?

Here’s how it looks if I hard code the class name:

```auto

var newImage:Sprite=new ImgPowerExec() as Sprite;
imgcon.addChild(newImage)

```

But the thing is, I don’t want to have to write a giant switch statement that checks for every possible image: I’m sure there has to be a way to dynamically change “ImgPowerExec()” to whatever the value of, say, timeline.milestone[0].image happens to be?

I would greatly appreciate any advice! Thanks!!!
