PDA

View Full Version : AS3 and PHP help


Benji1298
12-15-2008, 10:39 PM
// Assign a variable name for our URLVariables object
var variables:URLVariables = new URLVariables();
trace("1")
// Build the varSend variable
// Be sure you place the proper location reference to your PHP config file here
var varSend:URLRequest = new URLRequest("http://moolagaming.byethost9.com/Jackpot.php");
trace("2")
varSend.method = URLRequestMethod.POST;
trace("3")
varSend.data = variables;
trace("4")
// Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
trace("5")
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
trace("6")
varLoader.addEventListener(Event.COMPLETE, completeHandler);
trace("7")
variables.Loss = loss;
trace("8")
variables.sendRequest = "parse";
trace("9")
// Send the data to the php file
varLoader.load(varSend);
trace("10")
// When the data comes back from PHP we display it here
function completeHandler(event:Event){
trace("11")
var jackpot = event.target.data.Jackpot
trace("12")
Jackpot.text = jackpot;
trace("13")
}



as of now this is my AS3 code.... in the output box i get:

1
2
3
4
5
6
7
8
9
10
Error opening URL 'http://moolagaming.byethost9.com/Jackpot.php'
Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()




and my php code is.....


<?



//Log onto MySQL server
$connect = mysql_connect("*****","*****","*****");
$database = mysql_select_db("*****") or die("Unable to select database");


//Get current value of Jackpot
$result=mysql_query("SELECT * FROM `Jackpot` WHERE 1");

$row = mysql_fetch_row($result);

$Jackpot=(float) $row[1]/100;

if($Jackpot<100){
$Jackpot=100;
}

//Add 5% of amount loss
$Loss = $_POST['Loss'];
$Loss = $Loss*0.05;
$Jackpot=$Jackpot+$Loss;

//Print Jackpot value for use in game
echo "Jackpot=".$Jackpot;

//Update MySQL server
$Update= mysql_query("UPDATE Jackpot SET Value=$Jackpot*100 WHERE 1");



?>

what's the problem!?!? please help... thanks

tBeck
12-20-2008, 04:47 PM
When loading URLVariables into flash; they must be in a name/value pair just like you would see in the browser kind of like this:

http://www.actionscript.org/forums/newreply.php3?do=newreply&noquote=1&p=822989

These variables both have a name and a value which they are associated with. So when you process your PHP Data you want to make sure that it follows this including special characters; you can do this by using http_build_query.


function http_build_query($a,$b='',$c=0){
if (!is_array($a)) return false;
foreach ((array)$a as $k=>$v){
if ($c) $k=$b."[".$k."]"; elseif (is_int($k)) $k=$b.$k;
if (is_array($v)||is_object($v)) {$r[]=http_build_query($v,$k,1);continue;}
$r[]=$k."=".urlencode($v);
} return implode("&",$r);
}


Use this function when you echo your data like:

echo(http_build_query("Jackpot=".$Jackpot;));