Hey. I want to do a for loop that grabs values from different variables. This function works nicely without the eval() statement (using the commented line below it) but not with it. What am I doing wrong? How could I make this work? Any help is much appreciated.
well, i need to somehow get the value of each variable (the alternate line just uses the text ‘blah’), which is why i need the eval statement. unfortunately, putting it in there makes the loop not run properly (it seems to stop after the first iteration)
Well, that’s not exactly what I wanted…
What I’d like to do is send all these variables’ values to the php script. That means that if the value of var1 is “cat”, var2 is “dog” and var3 is “bird”, then the url should read “savedata.php?var1=cat&var2=dog&var3=bird”.
[AS]var1 = “cat”;
var2 = “dog”;
var3 = “bird”;
function saveData() {
saveUrl = “savedata.php?”;
for (var i = 1; i<=3; i++) {
if (i>1) {
saveUrl += “&”;
}
saveUrl += “var”+i+"="+this[“var”+i];
}
loadVariablesNum(saveUrl, 0, “GET”);
}[/AS]
This works, well… with a set of 3 variables… to make it a dynamic amount of variables may require more work, depending on how exact these variables are being set.
*Originally posted by lostinbeta *
**Voetsjoeba: The title being “Looping <B>non-array</B> variables with eval()” I am assuming he doesn’t want to use arrays. I could be wrong. **
funny. if i add the three lines that set the variables to dog cat and bird, it makes my script work, which is odd because the textboxes are in the main timeline, where the script is, so if i have values typed in, that should work the same way, no?
ok… this might give a hint. in the textbox that displays the resulting string, saveUrl, the text is set to be red. But the value calculated for the first this[] or eval[] term is always black for some reason, and that’s where it cuts off. could i have buggy software or something?
no dice… i commented out that entire line (the one with the if statement) and it gave the same effect - the first value appended (shown in a different color), with nothing else after it
ok. i don’t know how to post a file here, so here’s a link. you can view the swf or download the fla. by the way, are flash source files compatible between mac and pc versions?