if you've got MX the LoadVars object is much better as you can set it up with a callback function that runs when it's finished accessing the server, and you just pass and recieve all your variables inside an object.
/* I want to create a server communications class, or set of functions
that encapsulate the LoadVars mechanism, ideally I'd like a function
that returns an object/array with the values in, or false on fail
OK - there's no sleep function in flash so here's the plan
STOP the current frame, then PLAY in the onload func and check the values in the next frame
in jScript functions OBJECTS, ARRAYS and FUNCTIONS are passed by reference, but scalars aren't
so I'm going to have to throw an object at this thing to which the extra field
loadedfine is added to signify that the server action happened
*/
// vars is an object with the values to be sent, method is "GET" or "POST"
function server_get_vars(url, vars, method)
{
stop();
if (!method) method = 'POST';
var lv = new LoadVars();
for (var i in vars) // copy the vars into the lv object
lv[i] = vars[i];
/* in FIREFOX it seems this onData event definitely IS needed when
using local file paths, not a server as host.
Given a bad filename onLoad is never called, but onData is.
Not needed for real servers localhost, so get shot
lv.onData(src)
{
// do stuff here
}
*/
vars.loadedfine = false; // default to badness
lv.onLoad = function(success) // set up the callback
{
if (success)
{
vars.loadedfine = true;
// copy the variables back into the object
for (var i in this)
vars[i] = this[i];
delete vars.onLoad; // superfluous
}
play();
}
var res = lv.sendAndLoad(url, lv, method);
if (!res) // an error has occured - play on
play();
}