Solved

things start before variables have been loaded from a text file

Posted on 2002-07-10
5
165 Views
Last Modified: 2010-04-03
I am loading around 1,000 variables from a text file. I am copying a movieclip 1,000 times and assigning the copied movieclips with a variable from the text file.

ie: mc1    varBat = 1
    mc2    varBat = 45
    mc1000 varBat = 12.5

varbat is taken from the text file.

my problem is flash starts to assign the variables before the text file is loaded (see code below). At the moment I load the text file and then have to click a button to copy the variables to the movieclips. I would like to do this as the movieloads.

loadVariables ("flash/1998bathy.txt","_root.mcChart");

var i = 0;

 do {
      i++;

      varBatNew = "varbat" + i
     newClip = "mc"+i;
      duplicateMovieClip ("_parent.mc", newClip, 2000-i);
      varSound = _root.mcchart[varBatNew].split(",");
      _root.mcChart[newClip]._x = convertE(varSound[0]);
      _root.mcChart[newClip]._y = convertN(varSound[1]);
      _root.mcChart[newClip].varDepth = varSound[2];
 } while (i<1071);

as you can see from my code my do loop isn't very effective. I know I have 1071 variables. Is there any way I van find out how many variables are stored in the text file as this fingure may change.

Any help greatly appreciated

0
Comment
Question by:neilwhite
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:mousefist
ID: 7143728
hey again!  this may not be the best way, but try this:

put a variable at the very end of the text file named "finishedLoading", and set it to some value ...
&finishedLoading=yes&
or something to that effect.  in flash, load the text file:
_root.mcChart.finishedLoading = "no";
loadVariables ("flash/1998bathy.txt","_root.mcChart");

and then loop around waiting for finishedLoading == "yes".  this way you won't have to guess how many variables are in the file, because finishedLoading will always be the last one.  just make sure that when you loop around, you don't loop back to the point where you loaded the textfile.  

you'll probably have to have the loop inside of mcChart, because you have to have the instance of it available to load the variables into it, but you don't want to start executing the rest of it (the part that uses the variables) until they're loaded.  in that case, the load stuff can go into the movieclip's onLoad event, and you don't have to worry about calling it twice.  good luck,

b!
0
 

Author Comment

by:neilwhite
ID: 7145407
Unfortunaetly this does work.

When I do the Do Loop the flash gives me the message, A script in this movie is Cause flash to run slowly...

Am I doing anything wrong?

_root.mcChart.varFinished = "no";

loadVariables ("flash/1998bathy.txt","_root.mcChart");

var i = 0;

 do {
 
     if (_root.mcChart.varFinished == "yes"){
           //Stuff

     }

 } while (_root.mcChart.varFinished == "no");
0
 
LVL 2

Accepted Solution

by:
mousefist earned 200 total points
ID: 7148364

you don't want to use a statement to loop around and wait for something, flash doesn't like that.  it could take several seconds to load a large file in, and flash will think you've stuck it in an infinite loop by that time.  instead, put on frame 3:

if (_root.mcChart.varFinished != "yes") {
    this.gotoAndPlay(2);
} else {
    this.gotoAndPlay(4);
}

... really this is overkill to show you what's happening, all you really need to say is

if (_root.mcChart.varFinished != "yes") {
    this.gotoAndPlay(2);
}

the rest is implied.  sorry i wasn't clear about that ... timeline loops are your friend!  remember to put the loadVariables call outside of this timeline loop so that you don't loop back around and re-call that statement.  hope that helps,

m!  b?
0
 

Author Comment

by:neilwhite
ID: 7148456
Excellent again!!! Many thanks!
0
 

Author Comment

by:neilwhite
ID: 7332889
A bit late
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

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
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.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

911 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

23 Experts available now in Live!

Get 1:1 Help Now