Copy link to clipboard
Copied
I am new in AS3, so please excuse a possibley easy question.
I want to update one entry in a matrix M. I use the commonsensical M[row][column]=1. It however has unexpected results:
The code is the following:
var m:Array = new Array()
var n:Array= new Array()
for (var i=0;i<3;i++) {
n.push(0);
}
for (var j=0;j<3;j++) {
m.push(n);
}
trace(m);
m[2][2]=34;
trace(m);
In the obtained matrix, more than one entry is updated and I obtain the following:
0,0,34,0,0,34,0,0,34
Any help?. Thanks
m is storing references to n, not three separate arrays. You'll get the same result if you change
m[2][2]=34;
to
n[2]=34;
Copy link to clipboard
Copied
m is storing references to n, not three separate arrays. You'll get the same result if you change
m[2][2]=34;
to
n[2]=34;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now