Preloader script

I’ve been reading a Flash help book, and it tries to explain how you can use Action script to create a preloader that will play a movie clips frames based on the amount of bytes loaded. I can’t seem to get it to work. Here is the code:

stop();
myInterval = setInterval(preloader,10);
function preloader() {
if (getBytesLoaded()>=getBytesTotal()) {
play();
clearInterval(myInterval);
}
myMovieClip.gotoAndStop(Math.round(_framesloaded/_totalframes*(myMovieClip._totalframes)));
}

This is on the first frame of my movie. I’ve also have a stop action on the first frame of my movie clip.

I’ve attached the FLA for dissection…any hints?

I didn’t download the .fla… But from viewing the source you posted… THis line looks funny…

myMovieClip.gotoAndStop(Math.round(_framesloaded/_totalframes*(myMovieClip._totalframes)));
}

The problem is… This will tell the movie to actually go to that frame and stop… Not play the movie until that frame… What you want is…


while(myMovieClip._currentframe != myMovieClip._totalframes)
{
   if(myMovieClip._currentframe != _root.framesloaded)
   {
      myMovieClip.play();
   } else {
      myMovieClip.stop();
   }
}

I’m pretty sure that is right… See if that works… It says… While the myMovieClip is running and the currentframes != totalframes… Chekc and see if anymore movie is loaded… If not… stop here… if so… play til it is. Someone double chekc me on this one.

I’ve tried this script and here are some of the problems…

I’m not exactly sure where I should put this? Does it take the place of the line that you said looks funny? Does it stand alone on the timeline?

Flash also tells me that this code will make the Flash player run slowly and my computer might become inoperative if I continue with it.

-Brock