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!

loadVariables is returning undefined result 1

Status
Not open for further replies.

frozenpeas

Technical User
Sep 13, 2001
893
CA
Hi,

Here is the code I am using:

Code:
loadVariablesNum("[URL unfurl="true"]http://www.mydomain/images/rdmimg.php",0);[/URL]
trace(_level0.pic);

My PHP script outputs:

Code:
pic="hdr.jpg"

I have tried outputting "level0.pic" from the PHP script. From Flash, I have tried loadVariables, I've tried adding a GET parameter, and various other things.

The trouble is that it traces "undefined" no matter what I do. Can anyone see what I am doing wrong?

Thanks.

frozenpeas
 
It's probably because you're trying to read the variable before it's loaded - the loadVariables command has to make a round trip to the server in order to produce a result but your trace statement will be executed on the same frame as the lv request so will have nothing to display yet. You can use an on(Data) event to wait for a server response or setInterval to add a delay before trying to read the value.

Better still if you're on MX or 2004 you can use loadVArs() instead of loadVariables which has an onLoad event built in which will fire your trace statement as soon as the variable is returned.
 
Thanks, wangbar. I'm pretty close now.

Code:
function showValues() {
  for (i in this) {
    _level0.pic = this[i];
	_root.text = _level0.pic;
  }
}
myLoadVars = new LoadVars();
myLoadVars.onLoad = showValues;
myLoadVars.load("[URL unfurl="true"]http://www.mydomain.com/fp/images/rdmimg.php");[/URL]

The problem now is that I need to get rid of onLoad = [type Function] being returned with my result. It replaces the value I need. What is the best way to remove that?

Thanks.

frozenpeas
 
Okay, I got it. I'm just calling the variables like this:

Code:
this.pic

frozenpeas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top