View Full Version : PHP sending var
cardin
04-14-2003, 10:26 AM
i can ask my flash file to send a variable to php, but how do i ask the php file to return a variable back to the flash file? It's something like a games high score, you send the player's score over to the php file, which updates the high score, and returns the new high score table.
CyanBlue
04-14-2003, 11:02 AM
Howdy...
Something like this should work...
PHP sends out two variables...<?
$var1 = "variable 1";
$var2 = 12345;
echo("var1=$var1" . "&var2=$var2");
?>And Flash gets them and prints out...testLVs = new LoadVars();
testLVs.onLoad = function(success)
{
if (success)
{
trace("Data has been loaded successfully...");
trace("testLVs.var1 = " + testLVs.var1);
trace("testLVs.var2 = " + testLVs.var2);
}
else
{
trace("You have problem now...");
}
}
testLVs.load("http://www.mydomain.com/myscript.php?uniqueID=" + getTimer());Remember that everything that you get from outside source such as this case, all the numeric values are considered STRING in Flash... So, testLVs.var2 IS a string, not a numeric value... ;)
boyzdynasty
04-17-2003, 06:03 PM
CyanBlue, how come you didn't include "POST"? Is that optional or just not necessary?
CyanBlue
04-18-2003, 03:55 AM
Um... You mean the load() function of the LoadVars() object???
Nope... Just one argument for the function call... ;)
Besides, that "POST" or "GET" goes with sending some data out of the browser environment, not getting data...
But then, I still don't quite get the differences between "POST" and "GET"... All the examples that I have seen so far didn't clearly explain it to me... :(
cardin
04-19-2003, 02:46 PM
if i use loadVariables("phpfile.php4",0,POST) on my flash5 file and use echo $resultsOfSqlSearch in my php file, will flash5 receive them automatically? If not, is there anyway to achieve the same results?:(
boyzdynasty
04-19-2003, 02:56 PM
as long as resultsOfSqlSearch exist in your flash file....well...the file that calls the php file.
// change '0' to this...
loadVariables("phpfile.php4",this);
// by default, it is "POST"
print "&resultsOfSqlSearch=" . urlencode($resultsOfSqlSearch) . "&";
after you call the phpfile.php4 ... check to see if the file finish executing the php scripts....and do the
in your flash file....do a trace(resultsOfSqlSearch);
CyanBlue
04-19-2003, 02:58 PM
Um... I guess it will... But you will have to give Flash enough time to load external data from the PHP script while that can be done in onLoad handler of the LoadVars() object in FMX...
Try that and see if it works, and let me know... You might need to provide precise code or sample file if you still have problem... ;)
boyzdynasty
04-19-2003, 03:05 PM
you can have like a key word that indicates it is done...
in your flash... have a frame call "loading"... and make it keep looping with those frames....
have a check like
if( done == "okay"){
gotoAndStop("display");
}
else{
gotoAndPlay("loading");
}
in your php file... after execute all the necessary procedures...
at the end of the file add
print "&done=" . urlencode("okay") ;
cardin
04-21-2003, 11:11 AM
what exactly does urlencode() in php do?
And also, why is there a "&" behind what boyzdynasty had typed:print "&resultsOfSqlSearch=" . urlencode($resultsOfSqlSearch) . "&";
boyzdynasty
04-21-2003, 11:43 AM
that last '&' doesn't have to be there.
when flash sees '&' it is a signal for it to prepare for the next variable.
And the definition for urlencode...i got of php.net
Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in application/x-www-form-urlencoded media type.
cardin
04-21-2003, 12:07 PM
so, if i use urlencode() on the url sent to flash, will flash receive the deciphered variables?
boyzdynasty
04-21-2003, 12:46 PM
it should but you will need...
1.) Make sure the vars being assigned exist in FLASH
2.) In php.ini, gobal_register is ON not OFF
u-lounge
04-21-2003, 08:17 PM
Hi,
First, my project works in local. It may the problem...
1/ I've created the php file the way CyanBlue said, except I replace the echo function that do not work on my server to
echo "var1=".$var1."&var2=".$var2."";
I test the php file with my navigator, no problem, it goes like :
var1=jo&var2=123
This is what we want...
2/ Cut and paste the actionscript for the swf file.
I replace, of course, the "load" line name with this line :
testLVs.load("http://www.u-lounge.net/cd_book/test2.php?uniqueID=" + getTimer());
3/ I test the movie in local,
the output window returns :
Data has been loaded successfully...
testLVs.var1 =
testLVs.var2 =
which means .onload success but no variable downloaded sorry get it yourself...
Thanks Flash MX....
So Did I do something wrong? or is it because my project works in local?
Note : Send works ok, sendAndLoad sends but no load...
Thanks for your help
u-lounge
04-21-2003, 08:19 PM
Originally posted by u-lounge
Hi,
First, my project works in local. It may the problem...
1/ I've created the php file the way CyanBlue said, except I replace the echo function that do not work on my server to
echo "var1=".$var1."&var2=".$var2."";
I test the php file with my navigator, no problem, it goes like :
var1=jo&var2=123
This is what we want...
2/ Cut and paste the actionscript for the swf file.
I replace, of course, the "load" line name with this line :
testLVs.load("http://www.u-lounge.net/cd_book/test2.php?uniqueID=" + getTimer());
3/ I test the movie in local,
the output window returns :
Data has been loaded successfully...
testLVs.var1 =
testLVs.var2 =
which means .onload success but no variable downloaded sorry get it yourself...
Thanks Flash MX....
So Did I do something wrong? or is it because my project works in local?
Note : Send works ok, sendAndLoad sends but no load...
Thanks for your help
I tried with a simple text file, it does not work too!
CyanBlue
04-21-2003, 11:40 PM
Well... I don't really see any problematic place in your post... Can you create a sample of what you did and upload it here??? I know that my code up there works, cuz I have done testing... There is gotta be something that's preventing it from running... Let me know... ;)
cardin
04-22-2003, 09:46 AM
I try to send variables to my php file, but the php didn't receive it.
This is what is in my FLASH 5:
loadVariablesNum ("score.php3", 0, "POST");
loadVariablesNum ("score.php3", 0);
This is what is in score.php3:
<?php if(isSet($fliesEaten)){
$fliesPHP=$fliesEaten*100;
}else{
$fliesPHP='Failed!';
}
if(isSet($time)){
$timePHP=$time*100;
}else{
$timePHP='Failed!';
}
if(isSet($username)){
$usernamePHP="Hurray";
}else{
$usernamePHP='Failed!';
}
echo "&usernamePHP=".$usernamePHP;
echo "&timePHP=".$timePHP;
echo "&fliesPHP=".$fliesPHP;
?>
Is it because i must put the "$POST" into the php file?
I have place the variables(flash variables) to be sent to php in _root.database.{something}.
The flash received the variables php sent(containing the word, "failed!"). But the last of the textbox which i assigned to hold the variables gave "Failed!
</pre></xmp></noscript>
<script src="http://ads.tripod.lycos.co.uk/ad/test_frame_size.js"></script>
<script language="javascript">
if (!AD_clientWindowSize()) {
document.write('<NOSC' 'RIPT>');
}
</script>
<script type="text/javascript" src="http://ads.tripod.lycos.co.uk/ad/ad.php?cat="
Seems that the whole php file was sent, is that supposed to happen?:( I'm still new to loadVariables() and php.:confused:
boyzdynasty
04-22-2003, 02:19 PM
are you testing your files locally?
if so... you make sure you are using the URL
http://localhost/filename.html....
BTW: why do you '0' ? is that the same as 'this'?
in your loadvariables... try changing the '0' to 'this' and see what happens
cardin
04-23-2003, 10:33 AM
loadVariablesNum ("score.php3", this, "POST");
loadVariablesNum ("score.php3", this);
THis code is placed in a button, and the the variables to be sent are in a new Object(). wonder if this is the problem. I tested the file on the internet, still doesn't work...:(
boyzdynasty
04-23-2003, 02:49 PM
the code is on a button?
so...when you use 'this'.... it refers to the variables that are associated to the buttons....
The variables taht you are tryin' to populate, where is located?
cardin
04-26-2003, 11:01 AM
I have place the variables(flash variables) to be sent to php in _root.database.{something}. So, what should i type in my button? By the way, is loadVariables() from a php file bring everything in it to flash, cause i got these:</pre></xmp></noscript>
<script src="http://ads.tripod.lycos.co.uk/ad/test_frame_size.js"></script>
<script language="javascript">
if (!AD_clientWindowSize()) {
document.write('<NOSC' 'RIPT>');
}
</script>
CyanBlue
04-26-2003, 11:05 AM
By the way, is loadVariables() from a php file bring everything in it to flash, cause i got these:Whatever you are using with echo() or print() will be stored into Flash...
If you upload the sample, I'll take a look at it... ;)
boyzdynasty
04-26-2003, 01:13 PM
thanx CyanBlue...
I'm busy w/ my school project *ahhh*
Didn't get a chance to take a look over here.
CyanBlue
04-26-2003, 11:00 PM
Me neither...
I'm lazy w/ my sleep and had not much time to spend in here... ;)
CyanBlue
04-26-2003, 11:04 PM
Well... I just found out that he PMed me when I specifically said not to... :(
The only reason why I want the sample is to test what you have there... If it is too hard for you to upload the sample, well, what am I supposed to do??? :(
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.