PDA

View Full Version : Submit scores not working


djdaz
06-29-2006, 08:33 PM
Trying to do a submit score thing using loadvars.sendandload. Thing is it's not working. can anyone see any errors here?


on (release) {
if (_root.playername <> "") {
dataOut = new LoadVars();
dataOut.Score=_root.totalscore;
dataOut.User=_root.playername;
dataOut.sendAndLoad("http://djs-stuff.barnsleydj.com/flash/games/barnsley/scoresend.php",_root.control,"POST");
_root.returnedmessage = _root.control.reply;
} else {
_root.returnedmessage = "Please enter your name!";
}
}


Thanks alot.
PS yeah i've searched but not found anything useful.

CyanBlue
06-29-2006, 08:56 PM
Howdy and Welcome... :)
Thing is it's not working.
I think it is abit vague for us to know what is not working and how it should be working... ;)
The only thing that I see missing is the onLoad handler...
on (release) {
if (_root.playername <> "") {
dataOut = new LoadVars();
dataOut.Score=_root.totalscore;
dataOut.User=_root.playername;
dataOut.sendAndLoad("http://djs-stuff.barnsleydj.com/flash/games/barnsley/scoresend.php",_root.control,"POST");
// I am assuming that _root.control is an instance of LoadVars object???
_root.control.onLoad = function (ok)
{
if (ok)
{
_root.returnedmessage = this.reply;
}
}
} else {
_root.returnedmessage = "Please enter your name!";
}
}

djdaz
06-29-2006, 09:09 PM
by not working i mean not sending the scores at all.

the _root.control is the movie clip where sendandload puts the variables passed back by PHP.

I'll try the code you gave me, thanks for that.

djdaz
06-30-2006, 12:24 AM
YAY got that working no problems,

now im trying to get the highscores back from PHP and put into a textArea

no the faintest what to do

CyanBlue
06-30-2006, 02:24 AM
YAY got that working no problems,
Can you at least explain what you did to fix the problem for other people who might have the same problem???
now im trying to get the highscores back from PHP and put into a textArea

no the faintest what to do
Create the PHP script that returns the all the highscores and use the same technique to display it... ;)

djdaz
06-30-2006, 01:36 PM
The fix was simple, i looked at your code, added a few things to mine and it all worked.

Heres the working solution.


on (release) {
if (sent) {
_root.returnedmessage = 'Score has already been sent';
} else {
if (_root.playername<>"") {
dataOut = new LoadVars();
dataOut.score = _root.totalscore;
dataOut.playername = _root.playername;
dataOut.onLoad = function(success) {
if (success) {
_root.returnedmessage = _root.dataOut.reply;
sent = true;
} else {
_root.returnedmessage = 'Error in score sending';
}
};
dataOut.sendAndLoad("http://djs-stuff.barnsleydj.com/flash/games/barnsley/scoresend.php", dataOut, "POST");
} else {
_root.returnedmessage = "Please enter your name!";
}
}
}

djdaz
06-30-2006, 02:07 PM
I've had a little go, but all i get in my textArea is undefined

Code is...


scoresIn = new LoadVars();
scoresIn.onLoad = function(success) {
if (success) {
namesArray = new Array();
scoresArray = new Array();
namesArray = this.scorenames.split("|");
scoresArray = this.scores.split("|");
for (var i:Number = 0; i<25; i++) {
_root.scoretable.text += i+'<tab><tab><tab><tab><tab><tab>'+this.namesArray[i]+'<tab><tab><tab><tab><tab><tab>'+this.scoresArray[i];
}
} else {
_root.scoretable.text = 'Error retrieving files';
}
};
scoresIn.load("http://djs-stuff.barnsleydj.com/flash/games/barnsley/scoreretrieve.php", scoresIn, "POST");
stop();


and the vars passed to the script from php can be found here.

http://djs-stuff.barnsleydj.com/flash/games/barnsley/scoreretrieve.php

thanks

CyanBlue
06-30-2006, 03:14 PM
You might want to remove the last '|' in the output so that it will spit out something like this from the PHP script...
scorenames=steve|dj|jon|bob|&scores=2212|2212|413|450|&
and use this AS...
scoresIn = new LoadVars();
scoresIn.onLoad = function(success)
{
if (success)
{
// trace(this);
namesArray = new Array();
scoresArray = new Array();
namesArray = this.scorenames.split("|");
scoresArray = this.scores.split("|");
trace("namesArray = " + namesArray);
trace("scoresArray = " + scoresArray);
for (var i:Number = 0; i < 25; i++)
{
_root.scoretable.text += i + '\t\t\t\t\t\t' + namesArray[i] + '\t\t\t\t\t\t' + scoresArray[i] + "\n";
}
}
else
{
_root.scoretable.text = 'Error retrieving files';
}
};
scoresIn.load("http://djs-stuff.barnsleydj.com/flash/games/barnsley/scoreretrieve.php", scoresIn, "POST");
stop();

djdaz
07-01-2006, 10:52 PM
nice one! all working now.

Thanks muchly for that :)