actionscript 3 - As3 - Script Error on Arrays -
please inspect me coding:
function createrandomlist():void { var newlist:array = [0,1,2]; var curlist:array = item[selectedlevel - 1] //selectedlevel = 1; var normal:int = curlist[0]; var tempboo1:boolean = false; var tempboo2:boolean = false; var tempboo3:boolean = false; while (curlist[0] + curlist[1] + curlist[2] > 0) { if (number(curlist[0]) == 0 && tempboo1 == false) { newlist.splice(newlist.indexof(0), 1); tempboo1 = true; } if (number(curlist[1]) == 0 && tempboo2 == false) { newlist.splice(newlist.indexof(1), 1); tempboo2 = true; } if (number(curlist[2]) == 0 && tempboo3 == false) { newlist.splice(newlist.indexof(2), 1); tempboo3 = true; } var temp:int = math.floor(math.random()*(newlist.length)); curlist[temp] -= 1; generatedlist.push(number(newlist[temp])); trace(item); } while (normal > 0) { var temp2:int = math.floor(math.random() * 3) + 1; generatednormal.push(number(temp2)); normal--; } }
my item [[5,0,0],[10,0,0]];
after became [[0,0,0],[0,0,0]];
i want duplicate array item new variable curlist
.
every time traces, returning item[0][0] decreasing 1, want use curlist temp array calculate new random array based on item[0].
ouput:
4,0,0,10,0,0 3,0,0,10,0,0 2,0,0,10,0,0 1,0,0,10,0,0 0,0,0,10,0,0
is there links between them, or problem? please help! if need more infoemation, please comment me!
you can clone arrays if want create new reference.
function clone( source:object ):* { var myba:bytearray = new bytearray(); myba.writeobject( source ); myba.position = 0; return( myba.readobject() ); } var a:array = [[0,0],[1,1]]; var b:array = clone(a); b[0] = [2,2]; trace(a) trace(b)
output
0,0,1,1 2,2,1,1
it works object, not arrays. more infos here : as3 - clone object
Comments
Post a Comment