i have some loop function for the game, this loop for open the 9 box, here the code
function random_item_2(coinsx)
{
var listItem:Array = new Array();
for (var i:uint=0; i<15; i++)
{
listItem.push(i);
}
ItemLeft = 0;
for (var x:uint=0; x<boardWidth; x++)
{
for (var y:uint=0; y<boardHeight; y++)
{
var thisItem:FirstBox = new FirstBox();
thisItem.x = x * IcardHorizontalSpacing + IboardOffsetX;
thisItem.y = y * IcardVerticalSpacing + IboardOffsetY;
var r:int = Math.floor(Math.random() * listItem.length);
thisItem.cardface = listItem[r];
listItem.splice(r,1);
thisItem.gotoAndStop(thisItem.cardface+2);
var itemFound = this.foundItem(thisItem.cardface);
if (itemFound == 50 || itemFound == 100 || itemFound == 250 || itemFound == 500 || itemFound == 1000)
{
var itemC = Number(coinsx) + Number(itemFound);
coinsx = itemC;
update_coins(Number(coinsx));
info_coinstext(String(coinsx));
trace('Gold Coins Found > '+itemFound);
}else if(itemFound!='Kosong'){
updateItem(itemFound);
trace('Item Found > '+itemFound);
}
addChild(thisItem);
ItemLeft++;
}
}
}
the problem is, 9 box open in one time, not one by one, i want to box open the box one by one, after the first box opened so the next box will open, here for some algo that i wanted
open the first box
delay 5 sec
open the second box
delay for 5 sec
how i can do that ?
To add the delay in your for loop you should write something like this:
By increasing the delay every time you set the timeout, the function will be called later.