Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old July 20th, 2007, 06:51 PM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
  #2 (permalink)  
Old July 21st, 2007, 10:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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");
  #3 (permalink)  
Old July 22nd, 2007, 03:08 PM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #4 (permalink)  
Old July 22nd, 2007, 03:16 PM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #5 (permalink)  
Old July 22nd, 2007, 03:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #6 (permalink)  
Old July 22nd, 2007, 07:34 PM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #7 (permalink)  
Old July 23rd, 2007, 10:29 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
  #8 (permalink)  
Old July 23rd, 2007, 10:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Oklahoma City, Oklahoma, USA.
Posts: 249
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beg. PHP 5 > Ch. 11 - fetch_field.php crater BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 January 2nd, 2007 12:20 PM
PHP Warning: PHP Startup: Unable to load dynamic l surendran Beginning PHP 1 May 29th, 2006 08:49 AM
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 10:57 AM
Error: movie.php & commit.php on p182-186, ch6 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 12th, 2004 02:48 PM
LoadVars chiraagb Flash (all versions) 2 May 6th, 2004 10:52 PM





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