variable = 0;
function change() { variable = 1; }
go = newVars(); go.onLoad = function(success) { trace("#First"); change(); } go.load('http://www.stackoverflow.com/variables');
trace("#Second"); trace(variable); // output = 0;
The problem is that it executes #Second before #First, which means that the object is not fullly loaded but the code continues nonetheless. Is there a way handle this? I have tried using a while loop, but this is ugly and makes flash crash.Is there any decent way to handle this, does it have to do with better code structure/program flow or is there a technical way to make it wait? Also note: This code is executed on the server side, which means there are no frames involved.
UPDATE: When projects get bigger, this gets very ugly, especially when you are retrieving mulitple things from a server, you have to use very deep nesting, you have to keep repeating the same code, example for buying a serial:
a.onload() {
if(moneyAmount > 10){
b.onload(pay) {
sendProduct();
d.onload(serial) {
print(serial);
}
d.load('www.so.com/getSerial');
} b.load('www.so.com/pay?amount=5');
}else{
c.onload(wallet) {
displayWallet(wallet)
}
c.load('www.so.com/getWallet);
}
} a.load('www.so.com/checkMoneyAmount');