?
Solved

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

Posted on 2004-04-15
16
Medium Priority
?
442 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 1000 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
 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

850 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