View Full Version : Quick help for a noobie
jmumm
April 19th, 2004, 07:13 PM
This is probably a very basic question but I am having trouble with it. When I load my variables from php and then try to trace it, it gives me undefined, but when I go to list variables it says my variable arraystring is there in level0. How do I call variable arraystring? Here is my code.
lv = new LoadVars();
lv.load("http://www.jmumm.net/heather/directory.php");
trace(this.arraystring);
kode
April 19th, 2004, 07:49 PM
Use the onLoad event to ensure that the file has been loaded when you attempt to get the variable(s).
lv = new LoadVars();
lv.onLoad = function(success) {
if (success) {
trace(this.arraystring);
} else {
trace("Error loading file");
}
};
lv.load("http://www.jmumm.net/heather/directory.php");
jmumm
April 19th, 2004, 08:55 PM
Yes, I can trace it inside the onLoad event, but how do I get that variable outside of the function ?
kode
April 19th, 2004, 09:00 PM
The variable is defined in the object you used to load the file. So, if the name of the LoadVars object is "lv" and the variable name is "arraystring", you'd use "lv.arraystring".
jmumm
April 19th, 2004, 09:06 PM
Here is my code:
lv = new LoadVars();
lv.onLoad = function(success) {
if (success) {
trace(this.arraystring);
} else {
trace("Error loading file");
}
};
lv.load("http://www.jmumm.net/heather/directory.php");
trace(lv.arraystring);
When I run my code, it traces lv.arraystring first and shows it as undefined, and then it traces this.arraystring in the function and that works fine. I still can't get it to work.
kode
April 19th, 2004, 09:09 PM
It's because the file hasn't been loaded yet. That's what the onLoad event is for. :pa:
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.