PDA

View Full Version : retrieve highscore form PHP to Flash


Vjeko
01-12-2008, 12:17 PM
I've been searching solution for a week now. There are few problems.

1. I'm trying to save highscore from Flash to PHP (WORKS)
2. I'm trying to retrieve highscore form PHP to Flash (LOSING MY SANITY)

So my sending variables works, but getting them back doesn't.

Here's the code:
/*
*getMyResults()
*This method is for getting the results from PHP
*
*/
private function getMyResults():void
{
var myLoader:URLLoader = new URLLoader();
var myRequest:URLRequest = new URLRequest("Database/highscore.php");

myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myLoader.load(myRequest);
myLoader.addEventListener(Event.COMPLETE, onDataLoad);
}

/*
*onDataLoad()
*This method fills text boxes in fla file with retrieved data
*
*/
private function onDataLoad(event:Event):void
{
var loader1:URLLoader = URLLoader(event.target);
for(var i:Number = 0; i < loader1.data.cant; i++)
{
this["Ime"+i].text = loader1.data["Ime"+i];
this["Bodovi"+i].text = loader1.data["Bodovi"+i];
}
//tracing loaded data
trace(loader1.data);

//this is irrelevant - only graphic for game
otkriRezultate();
isponova_btn.visible = true;
isponova_btn.enabled = true;
isponova_btn.addEventListener(MouseEvent.CLICK, ponovo);
}


Ok, here is the deal. If I have absolute path in URLRequest:
var myRequest:URLRequest = new URLRequest("http://localhost/zapamtiMe/Database/highscore.php");
it WORKS! But only on my machine. When I upload it to internet (on my server) it doesn't work. (I change the path of course).

I don't get why relative path won't work on my machine or anywhere.

When relative path is in the place, i load php code, not echoed values of that php code.

Example:
with relative:
%3C%3Fphp%0D%0Ainclude%20%27config%2Ephp%27%3B%0D% 0A%0D%0A%24result=mysql%5Fquery...

with absolute:
Ime0=Dibeste&Bodovi0=5424&Ime1=Proba&Bodovi1=5231&Ime2=Maroni&Bodovi2=5161&Ime3=TugaBugaKuga...

Ime means player's name, and Bodovi means player's score.

So relative path is returning php code. I don't get it.

With absolute code, it works when I test my movie in flash, I get results which I want, but PROBLEM is when I test on my localhost (html file) it stops and results are not written in flash.


HINT: It seems (by not loaded graphic which should load) that it stops on onDataLoad function.

I'll attach PHP code from highscore.php:
<?php
include 'config.php';

$result=mysql_query("SELECT Ime, Bodovi FROM ".$imetablice." WHERE 1 ORDER BY Bodovi DESC LIMIT 10");
$cant = 0;
while($row=mysql_fetch_array($result))
{
echo "Ime".$cant."=".$row['Ime']."&Bodovi".$cant."=".$row['Bodovi']."&";
$cant++;
}
echo "cant=".$cant."";
?>

I repeat, highscore.php is working fine, echoing the right thing on screen, but seems like Flash is messing with my head...
I have save.php which saves data to MySQL and it works fine (I also used URLLoader and relative path).

So it WORKS when I have absolute path to highscore.php and when I test it in Flash, anywhere else it DOESN'T WORK (localhost, web server...)

Can anyone help me?

I would be very grateful...

Vjeko

ASWC
01-12-2008, 12:54 PM
We sometimes lose ourselves with path problems with Flash when it comes to upload all our files and make them work. A good trick I use to make sure that my problems don't come from paths is copy my php in all my server directories and subdirectories and see if my Flash can read one. That seems silly but then I'm sure it's not the path and sometimes it made my PHP working! (then i check to see which PHP file was the one working).

Vjeko
01-12-2008, 02:04 PM
I still don't get the problem, but I've solved it.
I used save.php for sending and retrieving results.