Hello,
I’m trying to setup a simple query. Two buttons in a .fla, each button upon click sendAndLoad a different value. That value (_root.fromfla) is then passed (POST) to a php file and processed into a seperate variable (&fromphp). Now the flash file loads up the variable (&fromphp) and outputs into a textbox (_root.thebox).
This works for the first click, but the problem lies in all subsequent clicks. Example: btn1 is pressed, textbox reads Click1. btn2 is pressed, textbox read Click1, when it should read Click2. However, if I had started by pressing btn2, then the text box would always read Click2. Here is the code:
function sendandrecive(btndata)
{
_root.fromfla = btndata;
var loader = new LoadVars();
loader.onLoad = function(success) {
if(success)
{
_root.thebox.text = this["fromphp"];
}
}
var sender = new LoadVars();
sender.fromfla = _root.fromfla;
sender.sendAndLoad("http://localhost/testfla.php", loader, "post");
}
btn1.onRelease = function()
{
sendandrecive("click1");
}
btn2.onRelease = function()
{
sendandrecive("click2");
}
The PHP Code:
$fromfla = $_POST['fromfla'];
echo '&fromphp='.$fromfla;
It seems like once sendAndLoad is used once, it loads in the proper variables. However, when it is used again it will not overwrite existing variables.
I’m new to handling data to and from flash, so that is just a guess. Any thoughts?
Thanks!
You are facing the problem of data caching…
just clear your browser cache and it will work again…
Permanent solution:
create unique string each time … like…
calculate
unique=Math.random()*10000+1; // you can also use date object to generate unique values
ldr.sendAndLoad(“http://www.somesite.com/dataloader.php?id="+unique,rcvars,"POST”);
so each time the string is unique… browser contacts the server instead of the local cache
Thanks for the suggestion, it was a great idea, certainly not the first time the cache has cause problems. However, unfortuantly it didn’t fix this issue. 
Have any other ideas? Thanks again!
sender.fromfla = _root.fromfla;
unique=Math.random()*10000+1;
trace(unique);
sender.sendAndLoad(“http://localhost/testfla.php?id=”+unique, loader, “post”);
[QUOTE=sparkdemon;2333788]You are facing the problem of data caching…
just clear your browser cache and it will work again…
Permanent solution:
create unique string each time … like…
calculate
unique=Math.random()*10000+1; // you can also use date object to generate unique values
ldr.sendAndLoad(“http://www.somesite.com/dataloader.php?id="+unique,rcvars,"POST”);
so each time the string is unique… browser contacts the server instead of the local cache[/QUOTE]
not sure if this is the issue or not, but for some reason, that loadvars object may not be getting “reset” - and, I did simplify it by only using one LoadVars object - not sure if you need two for other reasons - it should work either way. And, I made post into POST - all caps. See if the following works:
var loader:LoadVars = new LoadVars();
loader.onLoad = function(success) {
if(success)
{
_root.thebox.text = this["fromphp"];
}
}
function sendandrecive(btndata:String):Void {
_root.fromfla = btndata;
loader.fromfla = "";
loader.fromfla = _root.fromfla;
loader.sendAndLoad("http://localhost/testfla.php", loader, "POST");
}
btn1.onRelease = function()
{
sendandrecive("click1");
}
btn2.onRelease = function()
{
sendandrecive("click2");
}
Thanks! Your code is much pretty than mine. =D Alas, still no success. It does feel like a ‘caching’ or resetting problem. I can get it to work if I have each script reference a seperate php file btn1 --> testfla.php and btn2 --> testfla2.php, but no luck if they both point to the same php file. Does that help any?
Have any other thoughts?
Thanks!
[QUOTE=creatify;2333837]not sure if this is the issue or not, but for some reason, that loadvars object may not be getting “reset” - and, I did simplify it by only using one LoadVars object - not sure if you need two for other reasons - it should work either way. And, I made post into POST - all caps. See if the following works:
var loader:LoadVars = new LoadVars();
loader.onLoad = function(success) {
if(success)
{
_root.thebox.text = this["fromphp"];
}
}
function sendandrecive(btndata:String):Void {
_root.fromfla = btndata;
loader.fromfla = "";
loader.fromfla = _root.fromfla;
loader.sendAndLoad("http://localhost/testfla.php", loader, "POST");
}
btn1.onRelease = function()
{
sendandrecive("click1");
}
btn2.onRelease = function()
{
sendandrecive("click2");
}
[/QUOTE]
hmmm, did you try sparkdemon’s example with the cache issue?
If this doesn’t work using localhost - try it on an actual web server or place the files in your local dir and view in a browser. Concatenating items to a string and running from the flash IDE usually doesn’t work (on a Mac at the least).
just replace the sendandreceive function with:
function sendandrecive(btndata:String):Void {
_root.fromfla = btndata;
loader.fromfla = "";
loader.fromfla = _root.fromfla;
var unique:Number = Math.random()*10000+1;
loader.sendAndLoad("http://localhost/testfla.php?id="+unique, loader, "POST");
}
if that doesn’t work… I’d need to get the files from you to test. This should work plain-as-day!