# Problem with loading random mc to stage

**URL:** <https://forum.kirupa.com/t/problem-with-loading-random-mc-to-stage/315140>\
**Category:** Uncategorized\
**Created:** [October 18, 2010, 8:41pm UTC](https://forum.kirupa.com/t/problem-with-loading-random-mc-to-stage/315140 "2010-10-18T20:41:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![krembo](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@krembo](https://forum.kirupa.com/u/krembo)\
**Post date:** [October 18, 2010, 8:41pm UTC](https://forum.kirupa.com/t/problem-with-loading-random-mc-to-stage/315140/1 "2010-10-18T20:41:00Z")

</div>

Hey guys,  
Simple question probably to most of you but i can’t get it to work, hope you can help.

so i have 3 mc’s in my library each with linkage “icon1”, icon2", icon3".  
what i’m trying to do is load one of them randomly in to the stage.

here’s the code i have so far:

```auto

//creating an array that holds the mcs
var iconsarray:Array = new Array("mc1","mc2","mc3");

//creating a random number to use for loading the mc
var randmc:Number = Math.round (Math.random ()*2)+0;

//this is just a string to hold the mc with the number, not used
var all:String = (iconsarray[randmc]); 

//defining the mc's
var mc1:icon1 = new icon1(); 
var mc2:icon2 = new icon2(); 
var mc3:icon3 = new icon3(); 

//this works fine
addChild(mc1);

//this spits an error:
//Error #1034: Type Coercion failed: cannot convert "mc2" to
//flash.display.DisplayObject.
addChild(iconsarray[randmc]);

//this trace works perfect and displays the random mc name i was looking for
//trace (iconsarray[randmc]);

```

what am i doing wrong?

thanks in advance 🙂
