View Full Version : sendAndLoad????
markw
May 16th, 2003, 11:16 PM
What is the correct way to refer to variables returned in a sendAndLoad operation? Php is returning a name=value& string which is being passed back into a LoadVars object called rtnVars. How should I then refer to the values to update the value of a text field?
Thanks
Mark
:-\
brainy
May 17th, 2003, 05:20 AM
well, it loads it back into the LoadVars object (unless you specified another object to load it to)
anyways, to refer to it simply use myLoadVars.name, i.e:
myTextField.text = myLoadVars.name;
markw
May 17th, 2003, 10:24 AM
Well that is what I thought but I can't populate the text field. In this example I have used a different LoadVars object to receive the reply. My php script returns simply lastName=Smith. I've tested this in a browser.
Here's the actionscript:-
// ActionScript Document
function dataLoad(){
//will post data eventually but not for testing
lvAddressData.sendAndLoad("hotels.php", rtnVars, "POST");
myTextField.text = rtnVars.lastName
}
//Run starts here
lvAddressData = new LoadVars();
rtnVars = new LoadVars();
dataLoad()
The text field has an instance name of myTextField. Should this be variable name instead. I have seen both methods mentioned. What is the difference?
Thanks, Mark
brainy
May 17th, 2003, 10:36 AM
ahh, you need to wait for the data to actually load before you can populate it. something like this:
function dataLoad() {
lvAddressData.onLoad = dataRecieved;
lvAddressData.sendAndLoad("hotels.php", rtnVars, "POST");
}
function dataRecieved(success) {
if (success) {
myTextField.text = rtnVars.lastName;
} else trace("Failed!");
}
lvAddressData = new LoadVars();
rtnVars = new LoadVars();
dataLoad();
markw
May 17th, 2003, 11:47 AM
I think we are getting somewhere, but I get the "Failed" trace.
My text field is set up as Dynamic Text and has instance name of myTextField. My php script returns lastName=Smith
Any more ideas?
markw
May 17th, 2003, 11:49 AM
What is the "success" passed to dataReceived??
brainy
May 18th, 2003, 11:36 AM
from the AS Dictionary:
Usage
myLoadVars.onLoad(success)
Parameters
success The parameter indicates whether the load operation ended in success (true) or failure (false).
for some reason its failing to send/load the data. im not sure why.
markw
May 18th, 2003, 04:01 PM
Should my text field have an instance name or variable name??
brainy
May 18th, 2003, 05:06 PM
well, using this code, instance name.
but that shouldn't cause the LoadVars object to fail! try removing that 'if' and see if that works. make sure the URL you're accessing actually works, and stuff like that.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.