-
[F8] SendAndLoad issue
I'm trying to send multiple sets of variables to a server script via a loop. Unfortunately only the last element of the loop actually gets process by the script although in theory they all should cause it sends all the variables one after another. How can I make the following actually work?
Code:
resp = new LoadVars()
vars = new LoadVars();
for (i=0; i<my_xml.childNodes.length; i++) {
vars.uid = _root["shirt" + i].shirt_contents.uid;
vars.xposition = _root["shirt" + i]._x;
vars.tid = tid;
vars.yposition = _root["shirt" + i]._y;
vars.eof = 0;
vars.sendAndLoad("formationproc.cfm", resp, 'POST')
if(i == (my_xml.childNodes.length - 1))
{
vars.eof = 1;
}
resp.onLoad = function(success) {
if(success) {
removeMovieClip(loader1);
removeMovieClip(blackout1);
gotoAndStop(1);
}
}
}
I'm assuming there must have to be a delay to allow the script to react but am not sure how to achieve it. The script does work as the last part of the loop does get processed correctly.
Any Ideas?
-
doubt anyone will ever find themselves in a similar situation but i managed to resolve this by creating a function out of the above code and re-calling it for every value of ' i ' only when a response was received from the server.
Code:
resp = new LoadVars()
vars = new LoadVars();
i = 0
save_players(i)
function save_players(i){
trace("i value:" + i)
vars.uid = _root["shirt" + i].shirt_contents.uid;
vars.xposition = _root["shirt" + i]._x;
vars.tid = tid;
vars.yposition = _root["shirt" + i]._y;
vars.eof = 0;
vars.sendAndLoad("formationproc.cfm", resp, 'POST')
if(i == (my_xml.childNodes.length - 1))
{
vars.eof = 1;
}
resp.onLoad = function(success) {
i = i + 1
if(i < my_xml.childNodes.length)
{
save_players(i)
}
else
{
removeMovieClip(blackout1);
removeMovieClip(loader1);
gotoAndStop(1)
}
}
}