-
onData or onLoad???
Hi there!
Since some time ago, I have developed a lot of Flash projects with database integration (even in PHP as will in ASP).
Though, there is something that bugs me... onData and onLoad events used in LoadVars. As you already know, the basic method to access an external script is:
PHP Code:
DataSender = new LoadVars();
DataReceiver = new LoadVars();
// put here the function to receive data sent back
DataSender.sendAndLoad ("scriptname",DataReceiver,"POST");
However you need to get ready to receive the data sent back to Flash (as commented above), by the script. Well, normally, I do that by using onLoad event, this way:
PHP Code:
DataReceiver.onLoad = function()
{ trace (dataReceiver);}
Ok, it works like a clock. However, it the server fails, sometimes Flash keep trying and waiting forever.
Then, I found out that using onData event, you can prevent server timeout, this way:
PHP Code:
DataReceiver.onData = function(src)
{
if (src == undefined)
{ trace ("server failed"); }
else
{ trace ("ok"); }
}
The problem is that, if you use onLoad you cannot prevent server failure. However if you use onData, you CAN prevent server failure but DataReceiver will not be loaded with content sent back to Flash for the script.
Anyone there know how to deal with that?
-
-
onLoad parses (escapes) the string and assigns it to the loadVars object.
onData doesnt' and passes the value to a single argument.
comment out either one - they both produce the same net.
Code:
var a=new LoadVars();
a.onLoad=function(){trace(unescape(this));}
a.onData=function(b){trace(b);}
a.load("somefile.ext");
AFAIK, that's the only difference.
-
heres a thought:
If you want to know whether the server has failed but still use (onLoad) use this trick. Define a variable WITHIN the onLoad handler for e.g var myNumber:Number = 10;
Then outside of this function define a setInterval which runs only once for e,g after 1- secs. In this function check the value of myNumber, if it is undefined..u know mosy likely there is some server problem