Simple logic situation that I cant comprehend the outcome of

Hi guys,
I am new to programming and I am having difficulty understanding why the following doesn’t come out the way I would expect it to.


var currentpiecea:Image=rowHolder[piecearow][pieceacolumn];
var currentpieceb:Image=rowHolder[piecebrow][piecebcolumn];
trace(rowHolder[piecearow][pieceacolumn].x); output is 10
trace(rowHolder[piecebrow][piecebcolumn].x); output is 20
rowHolder[piecearow][pieceacolumn]=currentpieceb;
rowHolder[piecebrow][piecebcolumn]=currentpiecea;
trace(rowHolder[piecearow][pieceacolumn].x); output is 20
trace(rowHolder[piecebrow][piecebcolumn].x); output is 10
rowHolder[piecebrow][piecebcolumn].x=currentpieceb.x;
rowHolder[piecearow][pieceacolumn].x=currentpiecea.x;

trace(rowHolder[piecearow][pieceacolumn].x); output is 20
trace(rowHolder[piecebrow][piecebcolumn].x); output is 20




if i store the .x and .y values of the array elements as new int vars, i dont have this issue.
it seems as if settinging rowHolder[piecebrow][piecebcolumn].x=currentpieceb.x;
changes the value of currentpieceb but i dont understand why would that be.

any insight would be greatly appreciated. i got the code to work the way i wanted but i feel i have a fundamental misunderstanding of variables. :crying: