Array Problem!

Ok, I have an external text File with a bunch of variables in it. I want to store these variables in an Array.

My code:

loadVariablesNum(“whatever.txt”, 0)
//say we have variables in the text file called test1, test2, test3.//

myArray = new Array();
myArray[0] = test1
myArray[1] = test2
myArray[2] = test3
trace(myArray[0])

Is there any reason why this shouldn’t work?? I know the variables are loading because I can call them without using arrays, also if I just put a sting such as “hello” in myArray[0], I can trace it. Otherwise I keep getting undefined. Any help is much appreciated, this is driving me crazy! Thanks.

this works perfectly

test1="some value";
myArray = new Array();
myArray[0] = test1;
trace(myArray[0]);

The problem might be that you don’t wait for your variables to load. your variables like test1 are undefinded in the first place and the script gets executed before they have time to load.
See using LoadVars with onData event handler.

I’m loading the txt file in the Main swf, but I’m not actually calling them until I load an external swf, so I know they have had time to load. And I’ve called the variable without the array in the same place and it loads fine. I know this all seems correct, but for some reason I can’t get it to work. I’ve tried loading the .txt file both of these ways:

  1. loadVaribalesNum(“movies/Text Files/Features.txt”);

  2. loadFeatureText = new LoadVars();
    loadFeatureText.load(“movies/Text Files/Features.txt”);

I’m stumped!!
Thanks for your response.

if you say that you can trace fine the variable… it means it loaded succesfully :)… this is proof enough.
Let’s see… An array[1] for instance is not a real variable… It’s a pointer. Your problem probably involves this.
you say that you can’t trace the value of array[1] wich was supposed to be the content of test1 variable.
try this. After you load your vars


myArray = new Array();
myArray[0] = test1;
otherVar = myArray[0];
trace(otherVar);

It should trace your test1 content… if not… then it should be something with the loadvars.
Sorry I can’t be of more help.

or could it be a scope issue? Where you you have the array… script? It should be in the _root on level0; loadVaribalesNum loads your vars on a level.

I don’t mean by any way of insulting you… my question may sound stupid to you maybe… but sometimes problems come form the most obvious issues :slight_smile:

Sorry, I forgot to add that to my script in my last message.

loadVaribalesNum(“movies/Text Files/Features.txt”, 0);

But yes, I was indeed loading it into _level 0 on the _root timeline.

You will by no means ever insult me by trying to help me. I am by no means an expert in Flash, so most of my mistakes are little obvious things. I do appreciate your help on this issue so far. I am in the process of trying out your suggestion in your previous post. Thanks again.

try:

loadVariablesNum("whatever.txt", 0)
//say we have variables in the text file called test1, test2, test3.//

myArray = new Array();
myArray[0] = loadVariablesNum.test1;
myArray[1] = loadVariablesNum.test2;
myArray[2] = loadVariablesNum.test3;
trace(myArray[0])

hope this helps

http://www.bokelberg.de/actionscript/28.html

Ok, I think I figured out what I was doing wrong. Here’s what I had before:

loadVariablesNum(“whatever.txt”, 0)
//say we have variables in the text file called test1, test2, test3.//

myArray = new Array();
myArray[0] = test1
myArray[1] = test2
myArray[2] = test3

on Button:
on (release) {
trace(myArray[0]);
} result = undefined

I guess I thought that as long as I was trying to call the array from somewhere else with a button after I knew the text file was loaded everything was ok, but the file was never getting loaded before I was trying to set the variables to the Arrays. So by putting this:

loadVariablesNum(“whatever.txt”, 0)

on Button:

on (release) {
myArray = new Array();
myArray[0] = test1
myArray[1] = test2
myArray[2] = test3
trace(myArray[0]);

That seemed to work just fine. Thanks for the help guys.