Skip to main content
Participating Frequently
September 7, 2007
Question

LoadVars and PHP

  • September 7, 2007
  • 23 replies
  • 1719 views
I'm trying to use LoadVars to bring a user ID into Flash from a PHP page and then put the user ID into a dynamic text box. The user ID is created from 2 separate numbers that are received via a form. The problem is that I can't get Flash to load the variable. If I hardcode a number in then everything works fine, but it Flash doesn't seem to like dynamically created variables.

php code that works:
<?php echo "&qID=54564656&"; ?>

php code that doesn't work. With this one the Flash text field is blank. It doesn't even read "undefined".
<?php
$subDB = substr($_POST["quizDB"], 4);
$qID = $subDB.$_POST["quizNum"];
echo "&qID=".$qID."&";
?>

Flash code:
fromQuiz = new LoadVars();
fromQuiz.load("test.php");

fromQuiz.onLoad = function()
{
ID_txt.text = fromQuiz.qID;
}


Thanks
This topic has been closed for replies.

23 replies

Inspiring
September 7, 2007
@clbeech: no flash doesn't require this format, lol

@SW : then I'm confused how its getting the value - I am not a PHP expert. But the $_POST global array is only populated by values sent by the post method. I guess it might be possible to assign them in php code... but that seems unusual to me if its possible.
clbeech
Inspiring
September 7, 2007
huh, you must be sending this somewhere else then?
SW_FuzeAuthor
Participating Frequently
September 7, 2007
They do have value (unless I don't understand what your saying). I can echo the $_POST['quizDB'] straight to the screen.
clbeech
Inspiring
September 7, 2007
@GWD: wow for sure man! I just assumed that it wasn't a corresponding variable, interesting, I love it, learn something new every day ;)

Yet still, Flash doesn't require this format right?

@SW: you need to send a value to be used with your $_POST in the PHP then the new value will be returned to the second LoadVar.
Inspiring
September 7, 2007
where you have

$subDB = substr($_POST["quizDB"], 4);

You need to have sent 'quizDB' as a value by the post method in order for the server to have access to that value in the script that its executing
Inspiring
September 7, 2007
@SW_Fuze: You're trying to access some POST variables. They don't exist unless you send them to the server.

SW_FuzeAuthor
Participating Frequently
September 7, 2007
GWD: Sorry, but I don't understand your solution using the sendAndLoad()
Inspiring
September 7, 2007
clbeech: No - you're also wrong about the variable name (if I understood your point correctly). The first ampersand is ignored and does not form part of the variable name.
Check this out:
var myLV:LoadVars = new LoadVars();
myLV.decode("&aa=helloworld");
trace(myLV.aa)
SW_FuzeAuthor
Participating Frequently
September 7, 2007
It will also work this way:

<?php

$qID = "5454545";
echo "&qID=".$qID."&";

?>
clbeech
Inspiring
September 7, 2007
Yeah for sure GWD, I was saying he was asking for the wrong variable name on the AS return side, I was just assuming he was sending something also, duh, I should have seen that :) good one.

@SW_Fuse: no that's not true, it can be any name, not starting with a number.