# Dynamically assign a class into an element in an array

**URL:** <https://forum.kirupa.com/t/dynamically-assign-a-class-into-an-element-in-an-array/322989>\
**Category:** flash\
**Created:** [June 12, 2011, 1:23pm UTC](https://forum.kirupa.com/t/dynamically-assign-a-class-into-an-element-in-an-array/322989 "2011-06-12T13:23:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![meetspin](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@meetspin](https://forum.kirupa.com/u/meetspin)\
**Post date:** [June 12, 2011, 1:23pm UTC](https://forum.kirupa.com/t/dynamically-assign-a-class-into-an-element-in-an-array/322989/1 "2011-06-12T13:23:49Z")

</div>

Hey guys,  
Not sure if the title of this topic is correct, but what I’m trying to do is store a movieclip inside each array element using a for loop.  
However, I have 2 movieclips to choose from and I want the movieclip to be randomly assigned to each element in the array.

Here’s what I have so far but the syntax is obviously wrong:

```auto

var enemyArray:Array = new Array();
var randomEnemyNo:int;
var noOfEnemyMC:int = 2;
			
for(var i = 0; i < 5; i++) {
	randomEnemyNo = (Math.floor(Math.random() * noOfEnemyMC) + 1);
	enemyArray* = new this["Enemy" + randomEnemyNo + "();"];
}

```

OUTPUT:

```auto

ReferenceError: Error #1069: Property Enemy1(); not found on RandomSpawn and there is no default value.
ReferenceError: Error #1069: Property Enemy2(); not found on RandomSpawn and there is no default value.

```

RandomSpawn is the name of my project.  
I have an “Enemy1” and “Enemy2” movieclip in my Library.

.FLA and .AS attached as a .ZIP.

Can anyone help?
