Solved

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

Posted on 2004-04-15
16
430 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Action Script commands 4 302
Flash movie or gif/animation? 3 846
Failed download 57 535
File conversion question 5 54
This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

707 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

14 Experts available now in Live!

Get 1:1 Help Now