View Full Version : Variable passes from .txt but not from .html or .php. Help.
Coriolan
10-25-2005, 08:54 PM
I'm trying to pass variables from a php script to my movie, but it just don't work. But if I try the exact same code using a .txt file, it works perfectly. I have a feeling that it has something to do with this urlencode thing, but (as you see) I'm not an expert. Help please.
Here's my AS code (got from Moock's book):
this.createTextField("msg", 1, 200, 200, 100, 20);
varGeter = new LoadVars();
varGeter.onLoad = function () {
msg.text = this.lastName;
}
varGeter.load("http://localhost/sender.php");
And here's my php code (got from Moock's book:) )
<?php
$lastName = Ronaldo;
echo $lastName;
?>
CyanBlue
10-25-2005, 09:11 PM
Howdy and Welcome... ;)
Your PHP file should write the output like this...
lastName=some name
Hence...
<?php
$lastName = Ronaldo;
echo "lastName=" . $lastName;
?>
Coriolan
10-26-2005, 01:00 PM
Thanks, but despite of the obvious error I have made, this is not the problem.
If I try to pass the data from a page with all the stuff (<HEAD>, <BODY> etc.), my variable will be "undefined", but if I use a simple file, saved as .php and this is all I have in it (what I've got from you, CyanBlue :) ):
<?php
$lastName = Ronaldo;
echo "lastName=" . $lastName;
?>
flash will get the variable nice and easy. Any ideas why?
CyanBlue
10-26-2005, 04:14 PM
If I try to pass the data from a page with all the stuff (<HEAD>, <BODY> etc.), my variable will be "undefined",
Is this what you are actually trying to do??? Can you post the exact PHP script for that???
Coriolan
10-26-2005, 04:30 PM
Actually I'm just trying to pass a variable to my swf movie in the most simple way. It's working now, thanks to you, but only if the only thing I write to the file is the piece of code shown above. Anything else I put there (other tags, such as <HEAD>), my variable in the movie will be "undefined". I hope it is clear now, if not, I'll paste everything here. Thanks anyway.
CyanBlue
10-26-2005, 04:46 PM
I guess my problem is that I don't understand why you are passing the HEAD tag to Flash... It'd help me if you post the code...
finchou
10-26-2005, 04:51 PM
maybe it outputs :
<html><body>lastName=finchou</body></html>
it should be :
<?php
$lastName = Ronaldo;
echo "&lastName=" . $lastName."&";
?>
try it first with
echo "&lastName=thisIsATest&";
Coriolan
10-26-2005, 05:03 PM
Okay, here are the codes and the results.
The HTML page which contains my php code (sender.html):
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
$lastName = Ronaldo;
echo "lastName=" . $lastName;
?>
</body>
</html>
----
If I bring this up in my brower, the result will be: lastName=Ronaldo
Perfect.
Now ActionScript (I have a text box with the instance name: msg)
----
varGeter = new LoadVars();
varGeter.onLoad = function () {
msg.text = this.lastName;
}
varGeter.load("sender.html");
---
The result will be: undefined. I'm totally confused, because if my HTML page contains nothing but the php code, it works fine. :confused:
CyanBlue
10-26-2005, 05:22 PM
Ah... NOW I see... :)
The problem is that Flash won't be able to understand what you are trying to do... Ideally, your PHP script should only contain the portion that needs to process... That HTML codes are making Flash confused... What I normally do is to create separate PHP files one for HTML use and another for Flash use...
One thing you can do is to add extra '&' around your output... This might work okay for you but will waste extra bandwidth and I don't really recommend that...
echo("&lastName=" . $lastName . "&");
Coriolan
10-26-2005, 08:56 PM
Now I understand the whole thing. Thanks a lot. :)
CyanBlue
10-26-2005, 09:03 PM
Did that work???
Coriolan
10-26-2005, 09:17 PM
Yes, it did, but I will use separate files instead if you say that's the way. Thanks again!
finchou
10-26-2005, 10:29 PM
ok that's just what I said in my own not-so-clear way...
glad it works
CyanBlue
10-27-2005, 02:00 AM
Oops... Sorry, finchou... I totally missed your reply in the thread... Yup... That's exactly what you have said there... :)
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.