Unfortunately, when one problem is solved, another one appears…
It seems that the variables that are dynamically created this way, are also dynamically deleted (perhaps at the same time as the other dynamic variable is created).
The problem now is that I need all the created variables to remain active at the same time, since they are loadVars-variables, with which I load text from textfiles to textfields.
for (i = 1; i < 5 + 1; i++){ root["loadText" + i] = new loadVars(); root["textFil" + i] = “MyTextFile_” + i + “.txt”; root["loadText" + i].load(root["textFil" + i]); root["loadText" + i].onLoad = function() {
_root[“root.txt” + i].html = true;
_root[“root.txt” + i].htmlText = this.my_text;
}
}
Well, the above code seem to actually load the text into the textfields for a second or so, but when the next loop kicks in, the text unloads again.
set is a top level function that sets a variable with the given name (which can be dynamically defined) in the current major scope and assigns it the value passed.
set(“variableName”, value);
is the same as
variableName = value;
because its a ‘top level function’ set is only specific to the scope in which its called… the ‘major’ scope. By this I mean if you are writing the script in the main timeline, the variable will be set in _root no matter what. You cant alter the scope at which set is set unless you write it directly within that scope. This means set only sets variables in movieclip objects since thats the only place you can physically write script. Within prototypes or within the function/method scope of other objects, set will still write the variable in the ‘major scope’ - the scope at which the script, as a whole, exists.
this[“info”+ii]
uses associative array referencing. Its just a way of referencing a variable (any scope) using strings (and therefore more dynamially) For more on that you can go see
I feel a bit like GW Bush when reading your post (dyslectic, that is…or maby just plain stupid ), but if I understand you correctly I should be able to create two loadVars -variables (in my code above) with the set -method that will be active (ie. not deleted when the loop enters another loop) the whole time, and then just reference them with the _root[] -array?
Something like this, perhaps?
for (i = 1; i < 5 + 1; i++){
set(“loadText_” + i, new loadVars());
set(“textFil_” + i, “MyTextFile_” + i + “.txt”); root["loadText" + i].load(root["textFil" + i]); root["loadText" + i].onLoad = function() {
_root[“root.txt” + i].html = true;
_root[“root.txt” + i].htmlText = this.my_text;
}
}
This way, two persistent variables should be created at each loop (“loadText_i”, and “textFil_i”), or have I missed something?
EDIT: Well, I must have missed something, since I cant get this to work.