# AS3 - dynamic class names with \*new\* operator?

**URL:** https://forum.kirupa.com/t/as3-dynamic-class-names-with-new-operator/196040
**Category:** flash
**Created:** [August 4, 2006, 7:57pm UTC](https://forum.kirupa.com/t/as3-dynamic-class-names-with-new-operator/196040 "2006-08-04T19:57:31Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ignitrix](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ignitrix/32/2664_2.png) [@ignitrix](https://forum.kirupa.com/u/ignitrix)
#### Post date: [August 4, 2006, 7:57pm UTC](https://forum.kirupa.com/t/as3-dynamic-class-names-with-new-operator/196040/1 "2006-08-04T19:57:31Z")

</div>

I’m using ActionScript 3 and Adobe Flash 9 Public Alpha.

I have 50 movie clips in the Library that use Linkage to set the Class name to: Img1, Img2, Img3, …, Img50.  
I have a parent class named RandImg. I want the constructor for RandImg to randomly select one of the 50 movie clips from the Library and display it. I could get this working by generating a random number, and then writing a really huge switch statement to associate each possible random number with its respective Library Movie Clip Class name, but I would much rather do this with a dynamic/variable class name based on the random number, such as:

var nImgChoice:Number = Math.floor( Math.random( ) \* 50 ) + 1;  
var mcImg:MovieClip = new [“Img”+String(nImgChoice)] ( );  
addChild( mcImg );

Note that this used to be possible in AS 2 by doing the following:

this.attachMovie( “Img”+String(nImgChoice) , “mcImg”, this.getNextHighestDepth());

Suggestions?  
Thanks,  
~JC
