# Using addChild with a variable

**URL:** <https://forum.kirupa.com/t/using-addchild-with-a-variable/280246>\
**Category:** Uncategorized\
**Created:** [January 24, 2009, 10:09pm UTC](https://forum.kirupa.com/t/using-addchild-with-a-variable/280246 "2009-01-24T22:09:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![BetaWar](https://avatars.discourse-cdn.com/v4/letter/b/e79b87/32.png) [@BetaWar](https://forum.kirupa.com/u/BetaWar)\
**Post date:** [January 24, 2009, 10:09pm UTC](https://forum.kirupa.com/t/using-addchild-with-a-variable/280246/1 "2009-01-24T22:09:25Z")

</div>

Okay, I am trying to use addChild on a current project I am working on, the only problem is that I have to add movieclips to the stage based on an array of movieclips given to me and a number (index).

At this point I am trying it like so:

```auto
var array:Array = new Array('Mc1', 'Mc2', 'MC3'); // etc.
var num:Number = 1;
addChild(array[num]);

```

I have exported all of my movieclips for actionscript and in the first frame.

The only issue that I am getting an error:

> TypeError: Error #1009: Cannot access a property or method of a null object reference.

and am not sure quite how to resolve it.

Any help would be greatly appreciated.  
BetaWar
