Load a texte file in a Array

Hi,

I would like to load the content of a texte file (i.e : value.txt)
in a Array.
I use :

onClipEvent (load) {
_global.testLoad = new Array()
gStartFrame = _root._currentFrame;
_global.valueSon = new LoadVars();
valueSon.load(“value.txt”);
valueSon.onLoad = function (etat) {
if (etat) { testLoad = valueSon.contenu ;
}
// trace(testLoad);
}
trace(testLoad);
}

there is a another code below this one , where i want to get the value of testLoad to use it.

but I can’t get the value in the second trace !!
i known that the variable is declare in function (so as, local) but i can find how to get the content of testLoad in the second trace, to use it later on in script.
Someone can help me ?
Thank

it’s because the code is excuted faster than the time it takes to load the .txt file. :wink:

by the way, if you actually want to save the variable into the array, you should use Array.push.

testLoad.push(this.contenu);
// instead of
testLoad = valueSon.contenu;

=)

Hi,

I try this that doesn’t work :

onClipEvent (load) {
_global.testLoad = new Array()
gStartFrame = _root._currentFrame;
_global.valueSon = new LoadVars();
valueSon.load(“value.txt”);
testLoad.push(valueSon.contenu);
valueSon.onLoad = function (etat) {
if (etat) {testLoad.push(this.contenu);
;
}
trace(testLoad);
}
trace(testLoad);
}

the second trace is still empty !

Someone know another way ? how to load value from texte file in a Array to use it in the texte file.

you access the variable using: testLoad[0]

there’s a thread in the best kirupa about arrays and multidimensional arrays. i think you should take a look at it. :wink:

trace(testLoad[0]);
undefined (in the debug out)

the value inside the value.txt are like (,0,5,9,9,8,5,6,5,0,4,9,9,9,3,8,…)

doesn’t work, i think the problem comes from the variable whois declare in the function.

What i would like is to get a array with all the value inside.

it works.

and if you want to get all the variables into the array, it would be something like this:

valueSon.onLoad = function(etat) {
if (etat) {
for (var vars in this) {
if (typeof this[vars] == "string") {
testLoad.push(this[vars]);
}
}
}
};

check this out! :wink:

Here is the full code that i want to use.
it is for synchronise a mouth with the value of sound ( in level)
that doesn’t work as indicated below.

onClipEvent (load) {
_global.testLoad = new Array()
gStartFrame = _root._currentFrame;
_global.valueSon = new LoadVars();
valueSon.load(“value.txt”);
testLoad.push(valueSon.contenu);
valueSon.onLoad = function(etat) {
if (etat) {
for (var vars in this) {
if (typeof this[vars] == “string”) {
testLoad.push(this[vars]);
}
}
}
};
// trace(testLoad);
trace(testLoad);
}

onClipEvent (enterFrame) {
gFrame = _root._currentframe-gStartFrame;
gAmp = testLoad[gFrame]; // <= here it doesn’t work
trace(testLoad); //here is work but not above gAmp
with (_root.mellisa.mouth) {
gotoAndStop(gAmp+1);
}
}

here is the value taht i have to load.
I can’t change it, it’s value of sound volume.