Problem with loading random mc to stage

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:



//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 :slight_smile: