how to make the new Array start at the same position as the previous and randomise only the newObjec
So i am currently trying to make 5 boxes/ships (3Blue and 2 Green)appear in a random position(1st-Gree,2nd- Blue,3rd-blue,4th-Green,5th-Green or in some other random way) i the upper corner of the stage.Make them move down.Then make a new 5 boxes and position them in the same starting position as the previous 5 and make only them get randomised (not with the previous 5,what it is doing at the moment).And do this while they are moving down. so the code so far i have is this :
import flash.events.Event;
var shipCount:Number;
var shipCount2:Number;
var shipArray:Array = new Array();
var shipArrayPosition:Array = new Array();
var counter:int = 0
var positionsX:Array = ["50","100","150","200","250",]
addEventListener(Event.ENTER_FRAME, everyFrame)
function everyFrame(ev:Event):void{
counter++
if(counter % 70 == 0){
doShips()
}
positionShips()
trace(shipArray.length )
}
function doShips() {
shipCount = 3;
shipCount2 = 2;
var gap = 10;
for (var i:int = 0; i < shipCount; i++) {
var s = new Ship;
shipArray.push(s);
//s.x = s.width/2 + (s.width* i) + gap*i
//addChild(s)
//shipArrayPosition.push(s);
}
for (var j:int = 0; j < shipCount2; j++) {
s = new Ship2;
shipArray.push(s);
}
var array:Array=new Array();
while (shipArray.length>0) {
var index:uint = Math.floor(Math.random() * shipArray.length);
array.push(shipArray[index]);
shipArray.splice(index,1);
}
shipArray = array;
//shipsArray has been randomized
for (var k:int = shipArray.length - 1; k >= 0; k--) {
shipArray
.x = positionsX addChild(shipArray
) }
}
function positionShips() {
for (var i:int = shipArray.length - 1; i >= 0; i--) {
shipArray.moveDown() //what the code in the Ship and Ship2 class does -> only: this.y += 3
}
}
and how to make them stay at one position.Not to move in any X position when the new 5 are added
