p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Flash (all versions) (http://p2p.wrox.com/forumdisplay.php?f=59)
-   -   LoadVars with PHP (http://p2p.wrox.com/showthread.php?t=60338)

132591 July 20th, 2007 06:51 PM

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

harpua July 21st, 2007 10:58 AM

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");

132591 July 22nd, 2007 03:08 PM

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

132591 July 22nd, 2007 03:16 PM

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

harpua July 22nd, 2007 03:51 PM

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

132591 July 22nd, 2007 07:34 PM

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

132591 July 23rd, 2007 10:29 AM

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

harpua July 23rd, 2007 10:54 AM

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"; ?>


All times are GMT -4. The time now is 11:08 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.