# "onLoad" function for loading text file?

**URL:** <https://forum.kirupa.com/t/onload-function-for-loading-text-file/59211>\
**Category:** Uncategorized\
**Created:** [July 29, 2004, 8:56am UTC](https://forum.kirupa.com/t/onload-function-for-loading-text-file/59211 "2004-07-29T08:56:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rabi](https://avatars.discourse-cdn.com/v4/letter/r/848f3c/32.png) [@rabi](https://forum.kirupa.com/u/rabi)\
**Post date:** [July 29, 2004, 8:56am UTC](https://forum.kirupa.com/t/onload-function-for-loading-text-file/59211/1 "2004-07-29T08:56:39Z")

</div>

```auto
//this is the array of texts as variable;
txtFile = new Array("", "text01", "text03");
txtLoaded = new Array();
//function for loading the text at once
for (i=1; i<txtFile.length; i++) {
 loadText = new LoadVars();
 loadText.load(txtFile*+".txt");
 //trace(txtFile*);
 loadText.onLoad = function(success) {
  if (success) {
   txtLoaded* = this.myText;
   trace(txtLoaded*);
   }
 };
}

```

This code works with the loading text file. But,  
My plan was… to load the texts file in an array of variable named [COLOR=Red]“txtLoaded\*”[/COLOR] and then call them in some dynamic textbox when I click the button respectively. But I am not able to call the variable [COLOR=Red]“txtLoaded\*”[/COLOR] or whatsoever at all… I simply couldnot understand what is wrong with this code?  
Is it variable scope problem? I could pass on to a function but that will read only the last iteration of for loop…thus giving me only the last text information stored in the [COLOR=Red]“txtLoaded\*”[/COLOR] Please suggest some thing… I shall be so happy… I have spent many hours banging my head alone… please suggest…

---

<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:** [July 29, 2004, 2:26pm UTC](https://forum.kirupa.com/t/onload-function-for-loading-text-file/59211/2 "2004-07-29T14:26:42Z")

</div>

Hey rabi, I had the exact same problem a few days ago.  
[http://www.kirupaforum.com/forums/showthread.php?t=63979&highlight=myArray](http://www.kirupaforum.com/forums/showthread.php?t=63979&highlight=myArray)  
Thx to some great coders on this forum, I got it fixed in no time. The problem in your code above is that the i counter gets increase as the loop continues. By the time you click a button, the counter is already above your array length.

---

<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:** [July 29, 2004, 6:26pm UTC](https://forum.kirupa.com/t/onload-function-for-loading-text-file/59211/3 "2004-07-29T18:26:40Z")

</div>

> [@bobdoe](#):
>
> Hey rabi, I had the exact same problem a few days ago.  
> [http://www.kirupaforum.com/forums/showthread.php?t=63979&highlight=myArray](http://www.kirupaforum.com/forums/showthread.php?t=63979&highlight=myArray)  
> Thx to some great coders on this forum, I got it fixed in no time. The problem in your code above is that the i counter gets increase as the loop continues. By the time you click a button, the counter is already above your array length.

Thank you verymuch for you reply. But still I couldnot get the array called txtLoaded\* out of that function [COLOR=Red]loadText.onLoad = function(){[/COLOR]

That means I couldn’t read [COLOR=Red]trace(txtLoaded\*); [/COLOR] when I keep it out of the function [COLOR=Red]loadText.onLoad(); [/COLOR] its kind a difficult… I am not able to think of a way to call it out…

anyway I hope you got my point… :puzzled:
