So, I got the random enemies to appear in random spots… Works perfectly… So, now that I got the code working flawlessly, I am trying to implement the randomization of the enemies with my key press. I am getting no errors, but the function that calls the randomization isn’t being called when I press the right arrow key button. What am I missing? Here is my code on the maintimeline:
_root.attachMovie("char_mc","char_mc",_root.getNextHighestDepth(),{_x:100, _y:100});
char_mc.onEnterFrame = function() {
var speed = 5;
if (Key.isDown(Key.RIGHT)) {
char_mc._x += speed;
var spotArray:Array = [spot1_mc, spot2_mc, spot3_mc, spot4_mc, spot5_mc, spot6_mc, spot7_mc, spot8_mc, spot9_mc];
var enemyArray:Array = ["enemy1_mc", "enemy2_mc", "enemy3_mc", "enemy4_mc", "enemy5_mc", "enemy6_mc", "enemy7_mc", "enemy8_mc", "enemy9_mc"];
function shuffleArray(array:Array) {
var i:Number = array.length;
var j:Number = 0;
var temp:Number = 0;
if (i == 0) {
return [0];
}
while (--i) {
j = Math.floor(Math.random()*(i+1));
temp = array*;
array* = array[j];
array[j] = temp;
}
return array;
}
function enemiesPlacement() {
shuffleArray(enemyArray);
shuffleArray(spotArray);
var randomSelection = Math.floor((Math.random()*spotArray.length))+1;//add 1 to prevent 0 result
trace("there will be "+randomSelection+" enemies");
for (i=0; i<randomSelection; i++) {
var spot_mc = spotArray*;
enemy_mc = attachMovie(enemyArray*, enemyArray*, _root.getNextHighestDepth());
enemy_mc._x = spot_mc._x;
enemy_mc._y = spot_mc._y;
trace(enemyArray*+" is placed on "+spotArray*);
}
}
}
};
enemiesPlacement();