# Referencing a Random MovieClip from an Array

**URL:** <https://forum.kirupa.com/t/referencing-a-random-movieclip-from-an-array/244195>\
**Category:** flash\
**Created:** [November 15, 2007, 2:46am UTC](https://forum.kirupa.com/t/referencing-a-random-movieclip-from-an-array/244195 "2007-11-15T02:46:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtsfestivus](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@mtsfestivus](https://forum.kirupa.com/u/mtsfestivus)\
**Post date:** [November 15, 2007, 2:46am UTC](https://forum.kirupa.com/t/referencing-a-random-movieclip-from-an-array/244195/1 "2007-11-15T02:46:17Z")

</div>

I know this has to be simple, but I can’t solve the problem. I’m trying to call a random MovieClip from the library each time the user clicks. The MovieClip names are stored in the array. I can get a single clip to work without the array, but not with. The main problem lies, I think, in trying to apply randomStar to currStar.

The tutorial this code references is [http://www.kirupa.com/developer/flashcs3/animating\_dynamic\_movieclips\_AS3\_pg1.htm](http://www.kirupa.com/developer/flashcs3/animating_dynamic_movieclips_AS3_pg1.htm)

Quick help? Thanks much in advance.

```auto
function Main() { 
stage.addEventListener(MouseEvent.CLICK, AddStar); 
} 
Main(); 

var starArray:Array = new Array("star01", "star02", "star03", "star04", "star05"); 
var randomStar = starArray[Math.random() * starArray.length]; 

function AddStar(e:MouseEvent):void {	
var currStar = new randomStar(); 
this.addChild(currStar); 
currStar.x = mouseX; 
currStar.y = mouseY; 
currStar.addEventListener(Event.ENTER_FRAME, PlayStar); 
} 
function PlayStar(e:Event):void { 
var starMC:MovieClip = MovieClip(e.target); 
} 

```
