Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LoadVars.sendAndLoad() 1

Status
Not open for further replies.

programingnoob

Technical User
Dec 31, 2002
71
CA
Hello,

I am still in the process of learning some actionscript, and is quite confused by the process of LoadVars.sendAndLoad(). I am trying to get the flash movie to request a url with some data using the post method, and download the responding page. I am, however, unable to do that. Btw, I am using flash with php. I do not have difficulty in the php part, but only the actionscript part. Is there an example out there that pinpoints this topic?

Thanks.
 
Here's a simple example of LoadVars:

Code:
getData = function () {
	// create object
	lv = new LoadVars();
	lv.onLoad = function(ok) {
		// this function is triggered when data (or an error) is received back from the server
		if (ok) {
			// put returned data in output window
			trace(this);
		} else {
			// or try again if it failed
			getData();
		}
	};
	// data you want to send is appended as a variable to the object
	lv.dataToServer = 'test string';
	// send  data to your script
	lv.sendAndLoad('handlingScript.php', lv, 'POST');
};
getData();
// 
stop();

Not sure I'm totally understanding your post though - if you're actually trying to download a full page from the server rather than just some data from a script you're better off using getURL().
 
Thank you for the straightfoward and easy to understand example. Well, I am trying to get flash to load variables ex: &n='asdf', or something like that. But then I am also wondering if i can load arrays off php.
 
You can't pull a whole array down intact unless you use Flash Remoting (and if you're new to this you don't want to go there!). If you need the information in array format you can build the array within the 'onLoad' function. The easiest way is probably to set the data coming in up like this with numbered indexes:

Code:
&n1=asdf&n2=qwer&n3=zxcv

...you don't need quotation marks as in your example above, then use a loop to add the vars to an array:

Code:
for(var i=0;i<10;i++){
arrayVal[i]=this['n'+i];
}

... which has a disadvantage in that you need to know how many values are coming in in order to set up the loop. Or you can treat the data coming in as an object and run through it with a 'for .. in' loop:

Code:
for(var i in this){
arrayVal[i]=this[i];
}

... which doesn't have that disadvantage but sets up an associative array rather than an indexed one - you can put an index in by adding a counter variable and using it to key the array:

Code:
var count=0;
for(var i in this){
arrayVal[count]=this[i];
count++;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top