Hi all,
Im currently making a small flash car game (think football manager with cars) and have run into a little lag problem when communicating with my mysql server through php.
This is my current code.
dynamic class scripts.actionScript.masterScript extends MovieClip{
var sendingVars:LoadVars;
var recievingVars:LoadVars;
function masterScript(){
_global.carMake = "";
_global.carBhp = 0;
_global.carHandling = 0;
_global.weight = 0;
_global.reliability = 0;
_global.aerodynamics = 0;
}
function loadCarStats(userCarId){
sendingVars = new LoadVars();
recievingVars = new LoadVars();
recievingVars.onLoad = function(phpLoaded){
if(phpLoaded){
_global.carMake = recievingVars.username;
_global.carBhp = recievingVars.bhp;
_global.carHandling = recievingVars.handling;
_global.weight = recievingVars.weight;
_global.reliability = recievingVars.reliability;
_global.aerodynamics = recivingVars.aerodynamics;
}
trace(_global.carMake);
}
sendingVars.sendAndLoad("http://localhost/cargame/scripts/php/cars.php"+userCarId,recievingVars,"POST");
}
function onEnterFrame(){
}
}
Now I know my mysql and flash are communicating the only problem is they are not communicating fast enough when I take this code off the timeline and put it into a stand alone .as file.
For example
_global.carMake = recievingVars.username;
will trace undefined, but if i trace just recievingVars.username on the onEnterFrame function after about two frames it will start tracing the value taken from the database.
The thing is this really doesn’t help me as
function loadCarStats(userCarId)
is being called from a serperate .as file only once in order to set up the car befor you modify it. The reason onEnterFrame is not an option is once the base car stats have been loaded you can change them but if they are constantly being called then no matter how many times you change them it will just revert to the base settings.
Has anyone experianced lag problems like this befor? The only solution I can think of is making a loop that will hold up the code until everything is loaded which I don’t really want to do would much rather get this method working properly.
Thanks in advance if anyone can shed some light on the situation.
Take it easy