 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Flash (all versions) section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 20th, 2007, 06:51 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
LoadVars with PHP
I am new to flash (Still on the 30 day trial of CS3) but I am not as new to PHP. I heard about this loadvars thing, and googled it, and it said with some code I could load the variables from a PHP file. I am trying that out, so here is my code.
Code:
//test loadvars function
testVarPhp = new LoadVars();
testVarPhp.load("http://www.gamepasta.com/testvar.php");
//make testVarText read the same as testVar.testvar
testVarText.text = testVarPhp.testvar;
I checked about 4000 times all the spellings of files and variables and the name of the text field and stuff. The text field displays the word "undefined" and I don't know what that means. When I checked the script for errors, it said it had none, so I have no idea what is going on, please help.
"Judge a man by his questions, not by his answers."
-Voltaire
__________________
\"Judge a man by his questions, not by his answers.\"
-Voltaire
|
|

July 21st, 2007, 10:58 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
try this. I will test if your vars are coming thru and you can track down the problem a little easier.
var testVarPhp:LoadVars = new LoadVars();
testVarPhp.onLoad = function(success:Boolean) {
if (success) {
trace(this.toString());
testVarText.text = testVarPhp.testvar;
} else {
trace("Error loading/parsing LoadVars.");
}
};
testVarPhp.load("http://www.gamepasta.com/testvar.php");
|
|

July 22nd, 2007, 03:08 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Alright thanks. Hopefully that will do it, but out of curiousity, why the colons? Are those for defining the type of variable it is or something?
"Judge a man by his questions, not by his answers."
-Voltaire
|
|

July 22nd, 2007, 03:16 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I still get the same result, and I really have no clue what the problem is.
"Judge a man by his questions, not by his answers."
-Voltaire
|
|

July 22nd, 2007, 03:51 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
the colons tell the function what type of variable to expect, like boleen, string, init.
variable:datatype
what does the trace statement say?
Sounds like flash isn't finding your php page or the data is not in correct format. Can you pull up your php page in your browser? want is that exact url, make sure that url is correct. Then copy and paste what your php page is writing to the browser so I can see how that content is formated. It should be writing out something in this format.
&testvar=myphpcontent
|
|

July 22nd, 2007, 07:34 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Oh, I found out why I messed up. I wasn't even really clear on how to use the loadvars function, thanks. And yeah, the url is correct. Ok, sry, I am a noob at flash. Thanks. Hopefully this works
"Judge a man by his questions, not by his answers."
-Voltaire
|
|

July 23rd, 2007, 10:29 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Only one more thing, for some reason, I have the code written out on my php page as:
[code]
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Test Loadvars, actionscript function</title>
</head>
<body>
<?php
echo "&testvar=Testing";
?>
</body>
</html>
[code]
And for some reason it is displaying the <Body> tag which is kind of wierd.
"Judge a man by his questions, not by his answers."
-Voltaire
|
|

July 23rd, 2007, 10:54 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
since all you are doing is retrieving information via script and this page will run in the background you do not need the html headers.
all you need on your php code to process whatever data and then write it to the page.
<?php echo "&testvar=Testing"; ?>
|
|
 |