For those unfamiliar with tree structures, tree structures are usually dynamic lists where every node has a pointer to two other nodes. They are arranged so it makes for faster searching and stuff and are very useful in programming languages that offer direct access to heap memory.
Although I don’t know if there would be benefits of making tree structures in AS would be of any help but I decided to have a go at it anyway. Since there are no pointers in flash I tried to just replace pointers to nodes with nodes themselves. Such things usually work in java I think because the language just automatically makes pointers for variables.
So in flash I tried it this way
[AS]class Node {
var nodeValue:Number;
var leftNode = new Node(0);
var rightNode = new Node(0);
public function Node(nodeValueArg) {
nodeValue = nodeValueArg;
}
}[/AS]
But I get errors, “A class’s instance variables may only be initialized to compile-time constant expressions.”. So I guess I make instances of a class in the class itself. Any suggestions how you would go about solving this?