# Flash as2 Can't get this to work. Shuffling an Array. Plese Look

**URL:** <https://forum.kirupa.com/t/flash-as2-cant-get-this-to-work-shuffling-an-array-plese-look/331319>\
**Category:** Uncategorized\
**Created:** [July 5, 2013, 2:34pm UTC](https://forum.kirupa.com/t/flash-as2-cant-get-this-to-work-shuffling-an-array-plese-look/331319 "2013-07-05T14:34:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Scholz](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@Jason\_Scholz](https://forum.kirupa.com/u/Jason_Scholz)\
**Post date:** [July 5, 2013, 2:34pm UTC](https://forum.kirupa.com/t/flash-as2-cant-get-this-to-work-shuffling-an-array-plese-look/331319/1 "2013-07-05T14:34:44Z")

</div>

I’m scratching my head here, what am I missing?

var enemyArray:Array = [“enemy1\_mc”,“enemy2\_mc”,“enemy3\_mc”,“enemy4\_mc”,“enemy5\_mc”,“enemy6\_mc”,“enemy7\_mc”,“enemy8\_mc”,“enemy9\_mc”,];  
var randomSelection = Math.floor((Math.random() \* myArr.length));  
trace("Random Display = " + enemyArray[randomSelection]);

What I am trying to do is this: I am trying to call a random enemy from the library, and when the random enemy is called, the enemy will appear in a random location on the main timeline. On the main timeline, I have 9 movieclips (spot1, spot2…spot9). The alpha is set to 0 for each spot.

So, a random enemy is called, and then the enemy is randomly placed in one of the nine spots. Here is my complete code on the main timeline:

\_root.inventory\_mc.\_visible = false;

//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\_root.attachMovie(“spider\_mc”,“spider\_mc”,spider\_mc.getNextHighestDepth());

var randomSpot:Number = Math.floor(Math.random()\*9);

\_root.spider\_mc.\_x = \_root[“spot”+randomSpot].\_x;  
\_root.spider\_mc.\_y = \_root[“spot”+randomSpot].\_y;

//\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

\_root.onEnterFrame = function() {  
if (Key.isDown(73)) {  
\_root.inventory\_mc.\_visible = true;  
}  
};

var enemyArray:Array = [“enemy1\_mc”,“enemy2\_mc”,“enemy3\_mc”,“enemy4\_mc”,“enemy5\_mc”,“enemy6\_mc”,“enemy7\_mc”,“enemy8\_mc”,“enemy9\_mc”,];  
var randomSelection = Math.floor((Math.random() \* myArr.length));  
trace("Random Display = " + enemyArray[randomSelection]);
