I am a bit confused by one expression:
var nodes:Array = new Array();
for (var i:int = 0; i<=3; i++)
{
var node:Node = new Node(i)
nodes.push(node);
}
trace(nodes[0].id + ":" + nodes[1].id);
Returned me 0:0 instead of 0:1 as I expected.
public class Node
{
public var id:int;
public function Node(id:int)
{
id = id
}
}
How this can be explained?
You are setting the argument called
idequal to itself, which is clearly not the intended behavior.When there are instance variables that have the same names as arguments, you need to be explicit about which variable you wish to set:
This would work too: