RopeGun
April 15th, 2005, 02:03 PM
Hello AS experts.
I am trying to create an array where each element is a different text string that is loaded from separate external text files. What I have below almost works -- I can load in and trace each of the different strings at each step of the loop, but I cannot get them to be plugged into each element of an array. See below for the output when running this script. I know the problem lies at the line where I wrote: Doesn't work!. Does anybody know what I need to have here to make this work?
function createTitleArray() {
var i:Number = 0;
var n:Number = Number(slideTotalLV.slideTotal); //from another LoadVars and is equal to "7" (an integer)
var slideTitleLV:LoadVars = new LoadVars();
var imgTitle:Array = new Array(n);
while (i < n) {
slideTitleLV.load("../var/info_" + i + ".txt"); //opens files named "info_0.txt", "info_1.txt", ... , "info_6.txt"
slideTitleLV.onLoad = function(success:Boolean) {
if (success) {
trace(slideTitleLV.title + " [from loop]"); //in each of the *.txt files there is a variable "title" that is equal to some text. These are traced correctly in the Output panel
}
}
imgTitle[i] = String(slideTitleLV.title); //Doesn't work! Here is where I am trying to place contents of each "title" variable in an element of an array.
i += 1;
}
trace("titleArray = " + imgTitle + " [end]"); //"undefined" gets traced as each of the seven elements in the array.
}
OUTPUT
titleArray = undefined,undefined,undefined,undefined,undefined, undefined,undefined [end]
First Test Title [from loop] // these seven rows were retrieved from the "title" variable from the "info_0.txt", "info_1.txt", ... , "info_6.txt" external file sequences.
Second Test Title [from loop]
Third Test Title [from loop]
Fourth Test Title [from loop]
Fifth Test Title [from loop]
Sixth Test Title [from loop]
Seventh Test Title [from loop]
What I want is for these last seven lines to be the elements in the array that has only "undefined" elements.
Please help...losing my mind
Regards,
-john
edited by digitalosophy: I wrapped your code in as tags, your post was very hard to read.
I am trying to create an array where each element is a different text string that is loaded from separate external text files. What I have below almost works -- I can load in and trace each of the different strings at each step of the loop, but I cannot get them to be plugged into each element of an array. See below for the output when running this script. I know the problem lies at the line where I wrote: Doesn't work!. Does anybody know what I need to have here to make this work?
function createTitleArray() {
var i:Number = 0;
var n:Number = Number(slideTotalLV.slideTotal); //from another LoadVars and is equal to "7" (an integer)
var slideTitleLV:LoadVars = new LoadVars();
var imgTitle:Array = new Array(n);
while (i < n) {
slideTitleLV.load("../var/info_" + i + ".txt"); //opens files named "info_0.txt", "info_1.txt", ... , "info_6.txt"
slideTitleLV.onLoad = function(success:Boolean) {
if (success) {
trace(slideTitleLV.title + " [from loop]"); //in each of the *.txt files there is a variable "title" that is equal to some text. These are traced correctly in the Output panel
}
}
imgTitle[i] = String(slideTitleLV.title); //Doesn't work! Here is where I am trying to place contents of each "title" variable in an element of an array.
i += 1;
}
trace("titleArray = " + imgTitle + " [end]"); //"undefined" gets traced as each of the seven elements in the array.
}
OUTPUT
titleArray = undefined,undefined,undefined,undefined,undefined, undefined,undefined [end]
First Test Title [from loop] // these seven rows were retrieved from the "title" variable from the "info_0.txt", "info_1.txt", ... , "info_6.txt" external file sequences.
Second Test Title [from loop]
Third Test Title [from loop]
Fourth Test Title [from loop]
Fifth Test Title [from loop]
Sixth Test Title [from loop]
Seventh Test Title [from loop]
What I want is for these last seven lines to be the elements in the array that has only "undefined" elements.
Please help...losing my mind
Regards,
-john
edited by digitalosophy: I wrapped your code in as tags, your post was very hard to read.