PDA

View Full Version : Passing var from Flash to HTML


choja78
03-11-2004, 09:42 AM
Hi there. I was going thorugh Tutorial 26 of the Intermediate level (Passing Variables around - Flash to HTML and back) and I can't seem to figure out why it is not working.

I downloaded the source files and extracted all files to my local folder but when I run the .fla the html page is not reading the php code.

For example in Flash I'm passing the varilabe 'value'.

I then send the variable using getURL:

//send variable
on (release){
getURL('http://localhost/middle.php4',_blank,'GET');
}

The middle.php4 conatins the following code
<title> Passing the Variable <? echo $value ?></title>

...and in the body contains a line:
The variable you should see is <? echo $value ?>

When looking this in the browser the <title> just prints it exactly has shown '<? echo $value ?>

where as the second line doesn't show the value at all (i.e. The variable you should see is *blank*)

I tried adding the line $value = $_POST['value'] but that didn't work.


Any other thoughts? Could there be something wrong with my PHP? I'm running on 4.3

nathanleyton
03-11-2004, 10:58 AM
the best built in function for communicating with flash/PHP is loadVars().. There is loads in the forum about it. but heres a quick example for you to look at.


sendvar = "testing";
VarSend = new LoadVars();
VarSend.sendvar = sendvar;
VarSend.onLoad = function(success) {
varreturn = this.varreturn;
trace (varreturn);
}

VarSend.sendAndLoad("http://localhost/login.php", VarSend, "POST");

This is for 2 way communication. It will Keep the PHP file hidden. If you want to open the PHP file for the user to see use.
VarSend.Send("http://localhost/login.php", VarSend, "POST");

Using POST will stop the variables appearing in the address bar. if you use GET they will show up. If you are in the MX debug enviroment it defaults to GET even if you use POST. But in all other enviroments it will use POST correctly.

And you PHP File something like this.


$recievevar = $_REQUEST['sendvar'];
echo "&varreturn=blahblahblah";


Nathan

p.s. this was typed quite quick so maybe a couple of typos.

choja78
03-11-2004, 01:30 PM
Thanks for the reply. It worked!!

I think the problem was using the $_POST['value'];

It now works with the $_REQUEST (ansd also the $_GET)

Thanks agian for your help. It's greatly appreciated!

:D