# Using an array to "pull out" random movieclips from the library

**URL:** <https://forum.kirupa.com/t/using-an-array-to-pull-out-random-movieclips-from-the-library/286249>\
**Category:** Uncategorized\
**Created:** [April 12, 2009, 7:54pm UTC](https://forum.kirupa.com/t/using-an-array-to-pull-out-random-movieclips-from-the-library/286249 "2009-04-12T19:54:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![quicksmack](https://avatars.discourse-cdn.com/v4/letter/q/fbc32d/32.png) [@quicksmack](https://forum.kirupa.com/u/quicksmack)\
**Post date:** [April 12, 2009, 7:54pm UTC](https://forum.kirupa.com/t/using-an-array-to-pull-out-random-movieclips-from-the-library/286249/1 "2009-04-12T19:54:45Z")

</div>

i am trying to pull out a random movieclip from the library and use “addChild” to add it to another movieclip on stage by using an array…

basically, i need to be able to create an array that has all the names of the movieclips i want to randomly pull out… and then randomly select a name from that array so i can use it to get the movieclip out…

i cant seem to be able to tell flash that the name in the array is referring to a movieclip in the library…  
which is why the code below returns an error…

```auto
// Add Placeholders
var tl_holder:MovieClip;
tl_holder = new HolderClass();
stageholder.addChild(tl_holder);
tl_holder.x = 116
tl_holder.y = 69

// Create Array
var characterArray:Array = ["bear", "cat", "rifle"];

// Count 3 Seconds and then run the "ac_TL" function
var tl_timer:Timer = new Timer(3000, 1);
tl_timer.addEventListener(TimerEvent.TIMER, ac_TL);
tl_timer.start();

// THIS IS WHERE THE PROBLEM IS...
function ac_TL(event:TimerEvent):void
{
    var tl_character = new characterArray[Math.floor(Math.random() * characterArray.length)]();
    tl_holder.addChild(tl_character);
}

```

what is the right way to code this?
