Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

things start before variables have been loaded from a text file

Posted on 2002-07-10
5
Medium Priority
?
171 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
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…
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 select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

670 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