I have a flash movie loading variables from a java servlet, and I have a question about how I can go about loading the data recursively.
The data is being loaded into a tree-like class, so I hope to be able to call the loading function recursively in order to populate the entire tree.
My difficulty is in making sure the variables from one load are loaded before the next iteration that declares a new loadVars object (with the same name). The code below seems to shoot through to the last possible Node before loading the data. Any ideas?
Thanks,
T
TreeClass.prototype.populate = function(currNode) {
nodeData = new LoadVars();
nodeData.onLoad = loadNodeData;
nodeData.goto = "getnodeinfo";
var i = 0;
while (i<currNode.childNodes.length) {
// Get nodeData relating to current child
if (nodeData.loaded != false) {
nodeData.nodeID = currNode.childNodes;
nodeData.sendAndLoad(appUrl, nodeData, GET);
}
}
function loadNodeData(success) {
if (success == true) {
// Instantiate Node Object
_root["Node"+nodeData.nodeID] = new NodeClass(nodeData.nodeID, nodeData.childNodes, nodeData.whoId, nodeData.whoType, nodeData.actions, nodeData.methodIn, nodeData.documents);
_root["Node"+nodeData.nodeID].dumpNode();
i++;
populate(_root["Node"+nodeData.nodeID]);
}
}
The data is being loaded into a tree-like class, so I hope to be able to call the loading function recursively in order to populate the entire tree.
My difficulty is in making sure the variables from one load are loaded before the next iteration that declares a new loadVars object (with the same name). The code below seems to shoot through to the last possible Node before loading the data. Any ideas?
Thanks,
T
TreeClass.prototype.populate = function(currNode) {
nodeData = new LoadVars();
nodeData.onLoad = loadNodeData;
nodeData.goto = "getnodeinfo";
var i = 0;
while (i<currNode.childNodes.length) {
// Get nodeData relating to current child
if (nodeData.loaded != false) {
nodeData.nodeID = currNode.childNodes;
nodeData.sendAndLoad(appUrl, nodeData, GET);
}
}
function loadNodeData(success) {
if (success == true) {
// Instantiate Node Object
_root["Node"+nodeData.nodeID] = new NodeClass(nodeData.nodeID, nodeData.childNodes, nodeData.whoId, nodeData.whoType, nodeData.actions, nodeData.methodIn, nodeData.documents);
_root["Node"+nodeData.nodeID].dumpNode();
i++;
populate(_root["Node"+nodeData.nodeID]);
}
}