• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 448
  • Last Modified:

loadVariablesNum("info.txt",0); variables into an array?

Is there a way to get the loadVariablesNum... variables into an array and then loop this array to check which varialbes are present and what there values are?

0
Tobbe070599
Asked:
Tobbe070599
  • 9
  • 5
  • 2
1 Solution
 
rascalpantsCommented:
if you have Flash MX or greater, then you can use LoadVars()...  this will allow you to process the data better...

I need more information about the project and your goals...  :)


rp
0
 
krishnaprathabCommented:
Hi,

Use the code below :

myLv = new LoadVars();
myLV.onLoad = function()
{
      ageArray = new Array();
      nameArray = new Array();
      ageArray = myLV.age.split(",");
      nameArray = myLV.names.split(",");
      for (var i =0; i<nameArray.length;i++)
      {
            trace("Name : " + nameArray[i]);
            trace("Age : " + ageArray[i]);
      }
}
myLV.load("info.txt");

The text file content is :

names=john,oman,bithu,xyz&age=10,12,13,15,18

Now your nameArray and ageArray contains the names and the ages of the persons.

Hope this answers your question.

Thanks,
KP
0
 
Tobbe070599Author Commented:
I'm just learning this... but I like to make things difficult for me. =)

First of all I dont get into the function...

Your code is loading "info.txt" with myLV.load() and at the same time calling the function and passing on the text from the textfile to the function, yes?

should I name the variables in the text file something special to get this to work?

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Tobbe070599Author Commented:
Ok, this is what I am doing.

I got a world map with all coutries as movie clips that I color if the country is present in the textfile.
What I'm trying to avoid is to have to write hundreds of "if"...


//this is what my textfile contains:

se=yes&no=no&fi=yes&de=yes&dk=yes&EOF=true



//Here I color the movie clips (countries)

function colorIt(country)
      {
            myColor = new Color (country);
            myColor.setRGB(0x639EE7);
            return;
      }
      

if (EOF == "true") {
      
      if(_root.no=="yes") {
            colorIt(_root.no_movie);
            stop();
      }
      
      if(_root.se=="yes") {
            colorIt(_root.se_movie);
            stop();
      }


// If the file is not loaded the movie loops back one frame until its the textfile is loaded //

else{       
      gotoAndPlay(15);
}

0
 
krishnaprathabCommented:
Hi,

Replace your code with this one :

myLv = new LoadVars();
myLV.onLoad = function()
{
     ageArray = new Array();
     nameArray = new Array();
     countryArray = myLV.country.split(",");
     valueArray = myLV.value.split(",");
     for (var i =0; i<countryArray.length;i++)
     {
          if (valueArray[i])
        {
            colorIt(countryArray[i]);            
          }                
     }
}
myLV.load("info.txt");

function colorIt(country)
{
    myColor = new Color (country);
    myColor.setRGB(0x639EE7);
    return;
}

The text file content now will be :

country=se,no,fi,de,dk&value=yes,no,yes,yes,yes

What you do here is make a country,value pair each country maps to a value like se maps to yes, no to no etc..

You need not check for loading and stuffs the code executes only when the text file is loaded. What it does it takes the country and value and creates an array and loope through the array and if a countries value is yes then calls your colorIt function with the country value as the parameter. Simple isn't it? :)

The only thing you have to take care is that your country , value pair in the text file is proper.

country=se,no,fi,de,dk
value=yes,no,yes,yes,yes

Here se maps to yes, no to no, fi to yes so...on....

Hope this answers your question.

Thanks,
KP
0
 
Tobbe070599Author Commented:
I get the message:

**Error** Scene=Europe, layer=Outlines, frame=16:Line 4: Operator '=' must be followed by an operand
          ageArray = new Array();

**Error** Scene=Europe, layer=Outlines, frame=16:Line 5: Syntax error.
          nameArray = new Array();
0
 
krishnaprathabCommented:
Change these lines :

ageArray = new Array();
nameArray = new Array();

to:

countryArray = new Array();
valueArray = new Array();

Thanks,
KP
0
 
Tobbe070599Author Commented:
I still get errors. =)

**Error** Scene=Europe, layer=Outlines, frame=16:Line 4: Operator '=' must be followed by an operand
          countryArray = new Array();

**Error** Scene=Europe, layer=Outlines, frame=16:Line 6: Syntax error.
          countryArray = myLV.country.split(",");

I'm very gratefull for you trying to help me...
0
 
Tobbe070599Author Commented:
When I write  trace("lkjdfal") above

countryArray = new Array();
valueArray = new Array();

I get:

**Error** Scene=Europe, layer=Outlines, frame=16:Line 4: Operator '=' must be followed by an operand
         trace("lkjdfal") 

Total ActionScript Errors: 1        Reported Errors: 1
0
 
Tobbe070599Author Commented:
Could it be that the text file is'nt loaded fast enough?
0
 
krishnaprathabCommented:
Hi,

The probelm is that yo are using Flash MX 2004 and the script has to be modified for MX2004. I havewritten this in Flash MX and it works perfect for me. Iam very buys right now will try to help you out may be day after.

Thanks,
KP
0
 
Tobbe070599Author Commented:
Thanks anyway!
0
 
rascalpantsCommented:
Tobbe,

I am confused why KP's solution does not solve your problem...    also, you are getting an error you your trace because you need a ";" at the end...  the code things you are trying to do something else...

anyway...  it seems that you have already closed the question....


good luck...

rp
0
 
Tobbe070599Author Commented:
I opened a new question to see if there is anyone who can help me find what the problem is...
0
 
Tobbe070599Author Commented:
It worked when I deleted all blank spaces, some junk must have been hiding in the code.

Thanks again
0
 
krishnaprathabCommented:
THATS GREAT !!!

-kp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 9
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now