Solved

things start before variables have been loaded from a text file

Posted on 2002-07-10
5
167 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Link puzzle piece images together and change color on hover 2 444
Stock Videos 17 336
Flash movie or gif/animation? 3 911
Adobe Flash player - Microsoft Edge 9 175
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
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 how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

856 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