Hi all.
I’m new to this forum, but I have a problem. I’m writing code that takes data from mysql that’s processed by a PHP script. It’s actually a bit bizarre, at least to me. Anyway, here’s some basic AS3 code that’s moving toward what I want to do:
var loader:URLLoader = new URLLoader();
var urlRequest:URLRequest=new URLRequest("receive.php");
//urlRequest.method=URLRequestMethod.GET;
// Read returned values from external source as variables
loader.dataFormat=URLLoaderDataFormat.VARIABLES;
// Listen for completion
loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(urlRequest);
//}
function onComplete(evt:Event):void {
// Stop listening for completion
loader.removeEventListener(Event.COMPLETE, onComplete);
trace(evt.target.data);
trace(evt.target.data.student_number2);
studentNumber1.text = evt.target.data.student_number1;
studentNumber2.text = evt.target.data.student_number2;
studentNumber3.text = evt.target.data.student_number3;
studentName1.text = evt.target.data.student_name1;
studentName2.text = evt.target.data.student_name2;
studentName3.text = evt.target.data.student_name3;
}
In the GUI, I placed a bunch of textfields on the stage and gave them instance names.
Here’s my PHP script:
<?php
$connect = mysql_connect(“localhost”, “root”, “yeahlikeimreallygonnatellya”);
mysql_select_db(“test”, $connect);
$result = mysql_query(“SELECT student_number, student_name FROM students”, $connect);
echo “throwaway=666&”;
$count = 1;
while($row=mysql_fetch_array($result)){
echo "student_number$count=$row[student_number]&
student_name$count=$row[student_name]&";
$count++;
}
echo “count=$count”;
?>
I have several very strange problems:
[LIST=1]
[]For some reason, the statement “trace(evt.target.data);” produces a whole pile of garbled text before the actual stuff that it’s supposed to show
[] Because of problem #1, I’ve had to include a throwaway variable at the beginning, otherwise the first variable I try to pass into AS3 comes back as undefined. This causes errors when I run my flash movie in the IDE, but when I run it from the browser it doesn’t seem to have any effect.
[/LIST]
But this is the strangest thing of all: whenever I make any changes to the database (and subsequently try to load data from different variables), the new variables come back as undefined. For example, let’s say that I add another entry to the database, and decide to load students 2, 3, and 4 instead of 1, 2, and 3. When I do that, any new data I’ve added comes back as undefined, even though when I view the PHP output in my browser, it looks just fine.
And now for the REALLY bizarre part: I’ll copy that output, paste it into my PHP script as an echo statement, comment everything else out, and my flash movie runs fine. Even though the output from the PHP script is exactly the same, it gives me errors.
Something strange is definitely going on here, and I can’t for the life of me figure out what it is. Any ideas?