Hi all,
i'm echoing variable in a PHP script which i get from a mySQL database to an AS3 flash file but i can only ever get undefined as the output when i try to trace any of the variables in flash. Here is my code...
PHP Code:
<?php
// get data from mysql database
include("admin/config.php");
$con = mysql_connect($dbHost, $dbUser, $dbPass) or trigger_error("Failed to connect to MySQL Server. Error: " . mysql_error());
mysql_select_db($dbDatabase) or trigger_error("Failed to connect to database {$dbDatabase}. Error: " . mysql_error());
$theQuery = mysql_query("SELECT * FROM flashArtists");
// result to be sent to flash AS3
$result = "";
for ($i = 0; $i < mysql_num_rows($theQuery); $i++)
{
if ($i != 0)
{
$result .= "&";
}
$thisRow = mysql_fetch_row($theQuery);
$result .= "name" . $i . "=" . urlencode($thisRow[1]);
$result .= "&songs" . $i . "=" . urlencode($thisRow[2]);
}
echo $result;
?>
the output of this when viewed in a browser looks like this...
Code:
name0=Jay+Z&songs0=20&name1=Madonna&songs1=35&name2=Oasis&songs2=51&name3=Eminem&songs3=72&name4=Michael+Jackson&songs4=65&name5=Metallica&songs5=96&name6=Tool&songs6=21&name7=Rage+Against+The+Machine&songs7=26&name8=Rolf+Harris&songs8=3&name9=Timmy+Mallet&songs9=5&name10=Boyzone&songs10=18&name11=Blue&songs11=6&name12=Rihanna&songs12=56&name13=Meatloaf&songs13=13&name14=Rachel+Black&songs14=2&name15=Kylie+Minogue&songs15=31&name16=Apparat&songs16=2&name17=Pet+Shop+Boys&songs17=17
This is my flash AS3 code
Code:
package
{
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
public class main extends Sprite
{
public function main()
{
var request:URLRequest = new URLRequest("bannerArtists.php");
var getVariables:URLLoader = new URLLoader();
getVariables.dataFormat = URLLoaderDataFormat.VARIABLES;
getVariables.addEventListener(Event.COMPLETE, completeHandler);
getVariables.load(request);
try
{
getVariables.load(request);
}
catch (error:Error)
{
trace("Unable to load URL: " + error);
}
}
private function completeHandler(event:Event):void
{
var urlVariables:URLVariables = new URLVariables();
urlVariables.decode(event.target.data);
trace (urlVariables.name0); // shows "undefined"
trace (urlVariables.songs3); // shows "undefined"
}
}
}
I've tried so many different ways to get this to work but nothing is helping.
I should say that i'm running this on a local server using WAMP until i get the code working and i'll then be uploading it to my webspace. Is it possible that my local server isn't set up right? Are there any settings which this code relies on which i should check in PHP, or Apache?
Can i get flash to cycle through all of the data it has in "urlVariables" to see what is in there? It might help with debugging my code.
Any help would be greatly appreciated.
Cheers
LL