Solved

things start before variables have been loaded from a text file

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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,…
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…
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 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.

743 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

12 Experts available now in Live!

Get 1:1 Help Now