Solved

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

Posted on 2004-04-15
16
431 Views
Last Modified: 2007-12-19
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
Comment
Question by:Tobbe070599
  • 9
  • 5
  • 2
16 Comments
 
LVL 22

Expert Comment

by:rascalpants
ID: 10836753
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
 
LVL 9

Expert Comment

by:krishnaprathab
ID: 10839776
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
 

Author Comment

by:Tobbe070599
ID: 10840696
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
 

Author Comment

by:Tobbe070599
ID: 10840944
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
 
LVL 9

Accepted Solution

by:
krishnaprathab earned 250 total points
ID: 10841137
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
 

Author Comment

by:Tobbe070599
ID: 10841227
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
 
LVL 9

Expert Comment

by:krishnaprathab
ID: 10841235
Change these lines :

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

to:

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

Thanks,
KP
0
 

Author Comment

by:Tobbe070599
ID: 10841257
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Tobbe070599
ID: 10841338
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
 

Author Comment

by:Tobbe070599
ID: 10841348
Could it be that the text file is'nt loaded fast enough?
0
 
LVL 9

Expert Comment

by:krishnaprathab
ID: 10841438
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
 

Author Comment

by:Tobbe070599
ID: 10841465
Thanks anyway!
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 10842049
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
 

Author Comment

by:Tobbe070599
ID: 10842074
I opened a new question to see if there is anyone who can help me find what the problem is...
0
 

Author Comment

by:Tobbe070599
ID: 10842550
It worked when I deleted all blank spaces, some junk must have been hiding in the code.

Thanks again
0
 
LVL 9

Expert Comment

by:krishnaprathab
ID: 10852585
THATS GREAT !!!

-kp
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now