# Multi sendAndLoad issues

**URL:** <https://forum.kirupa.com/t/multi-sendandload-issues/261777>\
**Category:** flash\
**Created:** [May 30, 2008, 7:23pm UTC](https://forum.kirupa.com/t/multi-sendandload-issues/261777 "2008-05-30T19:23:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![one\_way\_7](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@one\_way\_7](https://forum.kirupa.com/u/one_way_7)\
**Post date:** [May 30, 2008, 7:23pm UTC](https://forum.kirupa.com/t/multi-sendandload-issues/261777/1 "2008-05-30T19:23:10Z")

</div>

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:

```auto

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:

```php

$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!

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [May 30, 2008, 7:35pm UTC](https://forum.kirupa.com/t/multi-sendandload-issues/261777/2 "2008-05-30T19:35:48Z")

</div>

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](http://www.somesite.com/dataloader.php?id=%22+unique,rcvars,%22POST)”);

so each time the string is unique… browser contacts the server instead of the local cache

---

<div class="post-metadata">

**Author:** ![one\_way\_7](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@one\_way\_7](https://forum.kirupa.com/u/one_way_7)\
**Post date:** [May 30, 2008, 7:56pm UTC](https://forum.kirupa.com/t/multi-sendandload-issues/261777/3 "2008-05-30T19:56:58Z")

</div>

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=](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](http://www.somesite.com/dataloader.php?id=%22+unique,rcvars,%22POST)”);

so each time the string is unique… browser contacts the server instead of the local cache[/QUOTE]

---

<div class="post-metadata">

**Author:** ![creatify](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@creatify](https://forum.kirupa.com/u/creatify)\
**Post date:** [May 30, 2008, 9:21pm UTC](https://forum.kirupa.com/t/multi-sendandload-issues/261777/4 "2008-05-30T21:21:14Z")

</div>

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:

```auto

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");
}

```

---

<div class="post-metadata">

**Author:** ![one\_way\_7](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@one\_way\_7](https://forum.kirupa.com/u/one_way_7)\
**Post date:** [May 30, 2008, 10:17pm UTC](https://forum.kirupa.com/t/multi-sendandload-issues/261777/5 "2008-05-30T22:17:36Z")

</div>

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:

```auto

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]

---

<div class="post-metadata">

**Author:** ![creatify](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@creatify](https://forum.kirupa.com/u/creatify)\
**Post date:** [May 31, 2008, 3:40am UTC](https://forum.kirupa.com/t/multi-sendandload-issues/261777/6 "2008-05-31T03:40:39Z")

</div>

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:

```auto

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!
