all groups > flash actionscript > june 2005 >
You're in the

flash actionscript

group:

PHP



PHP SkidOvidiu
6/18/2005 8:44:20 PM
flash actionscript: Im haveing problems loading variabiles from PHP into flash into a dynamic text
field
I attached this code to a button:
on (release) {
loadVariablesNum("Musicpoll.php", 0, "POST");
}
the to the I gave the text box the variable name: /:Rock
but the variable won't load into the text field
what else do I have to do?


Re: PHP David Powers
6/18/2005 11:21:05 PM
[quoted text, click to view]

Put the code on the main timeline and use LoadVars. The following code
assumes you have given your button an instance name of "loadDets_btn",
and your text field an instance name of "rock_txt".

loadDets_btn.onRelease = function() {
getPoll.load("Musicpoll.php?ck=" + new Date().getTime());
};
var getPoll = new LoadVars();
getPoll.onLoad = function(success) {
if (success) {
rock_txt.text = this.rock;
} else {
rock_txt.text = "Couldn't load data";
}
};

The PHP script should look like this:

<?php
echo 'rock='.urlencode('This is the result of the rock poll');
?>

For more details on how to transfer data between Flash and PHP, visit my
site at http://computerbookshelf.com/php5flash/ and follow the link for
the sample chapter. It goes through the process of loading data from
PHP, and then shows you how to send data using a Flash form. The book
itself, of course, contains a lot more.

--
David Powers
Author, "Foundation PHP 5 for Flash" (friends of ED)
Co-author "PHP Web Development with DW MX 2004" (Apress)
Re: PHP SkidOvidiu
6/19/2005 7:35:30 AM
in my poll ill need more text fields
but with the php script u gave me it opens all in the same text field
the poll looks like this : http://skid.uv.ro/Poll/Musicpoll.swf
what I dont know is how to load/change php variabiles from flash mx
Re: PHP David Powers
6/19/2005 9:41:23 AM
[quoted text, click to view]

I go into this in much more detail in the book, but the basic principle
is this:

From PHP, you must send a single string of name/value pairs, separated
by ampersands (&). There must be no spaces or characters that cannot be
used in a URL, so you need to pass each of the values to urlencode. You
can build everything into a single string by using .= (a period followed
by an equal sign), like this:

<?php
$output = 'rock='.urlencode($rockResult);
$output .= '&rap='.urlencode($rapResult);
$output .= '&house='.urlencode($houseResult);
$output .= '&dance='.urlencode($danceResult);
$output .= '&classic='.urlencode($classicResult);
$output .= '&other='.urlencode($otherResult);

echo $output;
?>

When those values are received by Flash, each of the names in the
name/value pairs becomes a property of the LoadVars instance. So you
would adapt the onLoad function I gave you before like this:

getPoll.onLoad = function(success) {
if (success) {
rock_txt.text = this.rock;
rap_txt.text = this.rap;
house_txt.text = this.house;
dance_txt.text = this.dance;
classic_txt.text = this.classic;
other_txt.text = this.other;
} else {
rock_txt.text = "Couldn't load data";
}
};

The values sent by PHP become properties of the LoadVars instance. In
your case, I created a LoadVars instance called "getPoll". So once the
values have been loaded by Flash, "getPoll.rock" contains the value sent
from PHP as "rock".

I could have used "getPoll" inside the onLoad function, but since the
callback function directly refers to "getPoll", it's simpler to use
"this" instead.

--
David Powers
Author, "Foundation PHP 5 for Flash" (friends of ED)
Co-author "PHP Web Development with DW MX 2004" (Apress)
AddThis Social Bookmark Button