# Load a texte file in a Array

**URL:** <https://forum.kirupa.com/t/load-a-texte-file-in-a-array/20558>\
**Category:** flash\
**Created:** [May 10, 2003, 8:32am UTC](https://forum.kirupa.com/t/load-a-texte-file-in-a-array/20558 "2003-05-10T08:32:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![odysse\_1](https://avatars.discourse-cdn.com/v4/letter/o/4da419/32.png) [@odysse\_1](https://forum.kirupa.com/u/odysse_1)\
**Post date:** [May 10, 2003, 8:32am UTC](https://forum.kirupa.com/t/load-a-texte-file-in-a-array/20558/1 "2003-05-10T08:32:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 10, 2003, 9:08am UTC](https://forum.kirupa.com/t/load-a-texte-file-in-a-array/20558/2 "2003-05-10T09:08:46Z")

</div>

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.

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

```

=)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 10, 2003, 9:20am UTC](https://forum.kirupa.com/t/load-a-texte-file-in-a-array/20558/3 "2003-05-10T09:20:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 10, 2003, 9:25am UTC](https://forum.kirupa.com/t/load-a-texte-file-in-a-array/20558/4 "2003-05-10T09:25:05Z")

</div>

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. 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 10, 2003, 9:33am UTC](https://forum.kirupa.com/t/load-a-texte-file-in-a-array/20558/5 "2003-05-10T09:33:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 10, 2003, 9:37am UTC](https://forum.kirupa.com/t/load-a-texte-file-in-a-array/20558/6 "2003-05-10T09:37:48Z")

</div>

it works.

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

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 10, 2003, 9:47am UTC](https://forum.kirupa.com/t/load-a-texte-file-in-a-array/20558/7 "2003-05-10T09:47:53Z")

</div>

check this out! 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 10, 2003, 9:48am UTC](https://forum.kirupa.com/t/load-a-texte-file-in-a-array/20558/8 "2003-05-10T09:48:16Z")

</div>

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);  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 10, 2003, 10:04am UTC](https://forum.kirupa.com/t/load-a-texte-file-in-a-array/20558/9 "2003-05-10T10:04:15Z")

</div>

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