Copy link to clipboard
Copied
Hey everyone. I was wondering if anyone could help me. I am using as2 to pass a variable from flash to my php and nothing is being passed! Here is the action script code that I put on my button:
on (release)
{
amount.text=5;
form1= new LoadVars();
form1.amount= amount.text;
form1.sendAndLoad("http://mywebpage.com/test.php",amount,"POST");
}
Now the amount of "5" is being inputted into a dynamic text field with the variable and instance name of amount (which, in the future, will be hidden ). This is working fine when clicking on the button. What I am trying to do, without success, is to get this value of "5" to my test.php and have it echoed and it's just not happening . This is my php script:
<?php
$form_inp= $_POST['amount'];
if ($form_inp==''")
{
print "Nothing inputted <br>";
}
else
{
print "You have inputted: $form_inp";
}
?>
I'm getting "Nothing inputted" everytime.
I've already tried the different routes for the amount.text such as:
on (release)
{
amount.text=5;
form1= new LoadVars();
form1.amount= this.amount.text;
form1.sendAndLoad("http://mywebpage.com/test.php",amount,"POST");
}
and
on (release)
{
amount.text=5;
form1= new LoadVars();
form1.amount= this._parent.amount.text;
form1.sendAndLoad("http://mywebpage.com/test.php",amount,"POST");
}
etc.........
I've also tried changing the variable name in the sendAndLoad function from amount to form1 like this:
on (release)
{
amount.text=5;
form1= new LoadVars();
form1.amount= amount.text;
form1.sendAndLoad("http://mywebpage.com/test.php",form1,"POST");
}
and still nothing.
In my php file I even tried the GET instead of the POST and it still turns up nothing.
<?php
$form_inp= $_GET['monto'];
if ($form_inp=='')
{
print "Nothing inputted <br>";
}
else
{
print "You have inputted: $form_inp";
}
?>
Extra info: I have put the .swf file and the .php file on the same level in the same folder on my server just to be sure and the amount.text dynamic text field and the button are on the same level in the .swf file.
Can anyone shed some light on my situation.......... pretty please? I am at wits end!
Thank you soooo much.
Ok. So as not to leave this thread unanswered, after a looooooong haul of trial and error, I switched to as3 and started doing some testing. As it turned out the register_globals was set to off on my site and that's why I wasn't getting the variable passed with the $_POST in my php. So what I finally came up with is the following:
In my fla/swf doc:
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.net.sendToURL;
var urlVariables:URLVariables = new URLVariables;
urlVariables.amo
...Copy link to clipboard
Copied
you shouldn't attach any code to objects and you should use a different loadvars to send and receive data:
var sendLV:LoadVars=new LoadVars();
var receiveLV:LoadVars=new LoadVars();
yourbutton.onRelease=function
{
amount.text=5;
sendLV.amount= amount.text;
sendLV.sendAndLoad("http://mywebpage.com/test.php",receiveLV,"POST");
}
receiveLV.onData=function(src){
trace(src);
}
Copy link to clipboard
Copied
Ok. I took a day off in order to come back with a clear head and give this a try. This is what happens:
When I put the code above in my actionscript it throws back an error message saying that a function name is expected. So I gave it a name and wrote it like this:
var sendLV:LoadVars=new LoadVars();
var receiveLV:LoadVars=new LoadVars();
myButton.onRelease=function
(pass)
{
sendLV.amount= amount.text;
sendLV.sendAndLoad("http://mywebpage.com/receive_test.php",receiveLV,"POST");
}
receiveLV.onData=function(src){
trace(src);
}
With my php like this:
<?php
$receiveLV= $_POST['monto'];
if ($receiveLV==''")
{
print "Nothing inputted <br>";
}
else
{
print "You have inputted: $receiveLV";
}
?>
But nothing comes back. Then I thought that since I gave the function the name of "pass" that perhaps I should put it in the parenthesis on the bottom, like this:
var sendLV:LoadVars=new LoadVars();
var receiveLV:LoadVars=new LoadVars();
myButton.onRelease=function
(pass)
{
sendLV.amount= amount.text;
sendLV.sendAndLoad("http://mywebpage.com/receive_test.php",receiveLV,"POST");
}
receiveLV.onData=function(pass){
trace(pass);
}
Yet once again it gives me that nothing was inputted.
Now I REALLY don't know what's wrong. Any ideas? Thanks in advance for your help .
Copy link to clipboard
Copied
use:
var sendLV:LoadVars=new LoadVars();
var receiveLV:LoadVars=new LoadVars();
yourbutton.onRelease=function(){
amount.text=5;
sendLV.amount= amount.text;
sendLV.sendAndLoad("http://mywebpage.com/test.php",receiveLV,"POST");
}
receiveLV.onData=function(src){
trace(src);
}
Copy link to clipboard
Copied
Thanks alot for your time kglad........ still not working though. If you have any other ideas, I would love to hear them, if not, then I'll just keep plugging away until it yields to the pressure.
Copy link to clipboard
Copied
now, fix your php:
<?php
$amount= $_POST['amount'];
echo $amount;
?>
Copy link to clipboard
Copied
Still nothing kglad. I can't figure out why it's not getting passed over. I've tried a hundred different variations of everything but have come up with nothing thus far. I'll keep you posted. It's most likely a noob mistake I'm making somewhere.
And the effort continues!
Thanks again...
Copy link to clipboard
Copied
what's the url to your online files?
Copy link to clipboard
Copied
Hey kglad. I can give you the URLs but I don't think they will help as they are .swf files and a server side php script but perhaps you know something I don't. So here they are:
http://mirador.mx/oaxaca/disco/receive_test.php
http://mirador.mx/oaxaca/disco/discomunal.swf
Thanks again!
Copy link to clipboard
Copied
and what do i need to click to trigger what you think should call your php?
Copy link to clipboard
Copied
The button "corona" in the menu.
Copy link to clipboard
Copied
change the code on that button to:
var sendLV:LoadVars=new LoadVars();
var receiveLV:LoadVars=new LoadVars();
yourbutton.onRelease=function(){
amount.text=5;
sendLV.amount= amount.text;
trace("sending");
sendLV.sendAndLoad("http://mywebpage.com/test.php",receiveLV,"POST");
}
receiveLV.onData=function(src){
trace(src);
}
Copy link to clipboard
Copied
I think you hit on something kglad, "sending" does NOT show on the php script. What can I be doing wrong? Should I do some local tests using the output window or what do you suggest?
We're getting somewhere now! Getting excited! Thanks again for your help!
Copy link to clipboard
Copied
sending you can test in your flash program. if you fail to see "sending" in the output panel, you're not clicking "yourbutton" after that code executes.
Copy link to clipboard
Copied
Sending IS showing up on the output panel. I guess this means my php script is where the problem lies. Right?
Copy link to clipboard
Copied
now, upload the swf published with that trace code.
Copy link to clipboard
Copied
It's up but still nil.
Copy link to clipboard
Copied
when i click the corona bottle, i see no trace.
Copy link to clipboard
Copied
It's when you click "corona" on the menu. Not the bottle. "sending" shows up in the output panel when I export the flash from adobe but you don't see it when you click the .swf.
Copy link to clipboard
Copied
Just to make your day a little worse (sorry).. On a Mac using Firefox the link you posted looks like this:
(No menu, no nothing). Just the line "You have:" on a blank white page.
Copy link to clipboard
Copied
Yep. That's why I'm posting in the forum. This is the problem. But this is only a test php. The menu is at the other link I provided.
Copy link to clipboard
Copied
copy the code you're using for your corona button and paste it here.
Copy link to clipboard
Copied
Here it is:
but_corona.onRelease=function()
{
amount.text=5;
var sendLV:LoadVars=new LoadVars();
var receiveLV:LoadVars=new LoadVars();
sendLV.amount= amount.text;
trace("sending");
sendLV.sendAndLoad("http://mirador.mx/oaxaca/disco/receive_test.php",receiveLV,"POST");
}
receiveLV.onData=function(src){
trace(src);
}
Copy link to clipboard
Copied
that's not the code i suggested. use:
var sendLV:LoadVars=new LoadVars();
var receiveLV:LoadVars=new LoadVars();
but_corona.onRelease=function()
{
amount.text=5;
sendLV.amount= amount.text;
trace("sending");
sendLV.sendAndLoad("http://mirador.mx/oaxaca/disco/receive_test.php",receiveLV,"POST");
}
receiveLV.onData=function(src){
trace(src);
}
and copy and paste your php file code because i don't think you followed directions for that either.
Copy link to clipboard
Copied
Be nice kglad. I appreciate all your help but I'm not a kid doing this on my lap from mommy's house. I consider myself a noob at this programming but I've been out of college for 15 years now and I'm not completely lost. So believe me when I tell you that I have used and tested the exact codes that you have sent me but when they don't work I tweek them to do some more tests and try not to post so much. I've done this so many times now and the programming has changed some. I guess I could always scroll up and check out what you originally sent me but since I have already tried that, I think it counterproductive.
Right now my php code is:
<?php
$amount= $_POST['amount'];
echo "You have:" . $amount;
?>