Dropping multiple objects using an array in Actionscript?
- by Eratosthenes
I'm trying to get these fireBalls to drop more often, I'm not sure if I'm using Math.random correctly.
Also, for some reason I'm getting a null reference because I think the fireBalls array waits for one to leave the stage before dropping another one?
This is the relevant code:
var sun:Sun=new Sun
var fireBalls:Array=new Array()
var left:Boolean;
function onEnterFrame(event:Event){
if (left) {
sun.x = sun.x - 15;
}else{
sun.x = sun.x + 15;
}
if (fireBalls.length>0&&fireBalls[0].y>stage.stageHeight){ // Fireballs exit stage
removeChild(fireBalls[0]);
fireBalls.shift();
}
for (var j:int=0; j<fireBalls.length; j++){
fireBalls[j].y=fireBalls[j].y+15;
if (fireBalls[j].y>stage.stageHeight-fireBall.width/2){
}
}
if (Math.random()<.2){ // Fireballs shooting from Sun
var fireBall:FireBall=new FireBall;
fireBall.x=sun.x;
addChild(fireBall);
fireBalls.push(fireBall);
}
}