View Full Version : Load a texte file in a Array
odysse-1
May 10th, 2003, 04:32 AM
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
kode
May 10th, 2003, 05:08 AM
it's because the code is excuted faster than the time it takes to load the .txt file. ;)
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;
=)
odysse-1
May 10th, 2003, 05:20 AM
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.
kode
May 10th, 2003, 05:25 AM
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. ;)
odysse-1
May 10th, 2003, 05:33 AM
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.
kode
May 10th, 2003, 05:37 AM
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]);
}
}
}
};
kode
May 10th, 2003, 05:47 AM
check this out! ;)
odysse-1
May 10th, 2003, 05:48 AM
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);
}
}
odysse-1
May 10th, 2003, 06:04 AM
here is the value taht i have to load.
I can't change it, it's value of sound volume.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.