Solved

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

Posted on 2004-04-15
16
433 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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
 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
YouTube Link 10 358
Some Flash in IE doesn't display properly, but does in Chrome 4 624
Download Adobe Flash Player 6 63
How to add jQuery and JavaScript(s) into Dreamweaver? 1 254
I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
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.

813 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

10 Experts available now in Live!

Get 1:1 Help Now