Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trouble updating an entry in a matrix

New Here ,
Nov 05, 2013 Nov 05, 2013

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

TOPICS
ActionScript
312
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 05, 2013 Nov 05, 2013

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;

Translate
LEGEND ,
Nov 05, 2013 Nov 05, 2013
LATEST

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines