Multiple Preloader with x movies

Simply put all your movies to load and the corresponding targets/levels in the array moviearray. Remember: If you don't want the loaded clips to start immediatly after beeing loaded, you have to place a stop action in the first frame of the movie. frame 1: //provide a list with all your movies to load and the targets/levels to load into moviearray = new Array("movie1.swf","target1","movie2.swf","level2","movie3.swf","_level99"); //set the index of the first movie to load actMovieIdx = 0; frame 2: // get the next moviename and target/level moviename = moviearray[actMovieIdx++]; movietarget = moviearray[actMovieIdx++]; // load the given movie loadMovie(moviename, movietarget); // remember the time where we started loading to calculate the bytes per second starttime = getTimer(); frame 3: //get the actual loaded bytes actBytes = eval(movietarget).getBytesLoaded() || 0; // get the total bytes to load totBytes = eval(movietarget).getBytesTotal() || 100; // calculate the percentage loaded percent = Math.round(actBytes * 100 / totBytes); // calculate bytes per second loaded bps = Math.floor(actBytes * 1000 / (getTimer() - starttime)); frame 4: if( totBytes - actBytes > 10){//more bytes available, keep on loading gotoAndPlay(3); } else if(actMovieIdx < moviearray.length){//if we got more movies to load gotoAndPlay(2); } frame 5: // ready, go - here starts your movie
Tim Date: 03/07/2001

Very nice. The bps is based on the bytes loaded over the time for one movie and is reset for each movie. As such we are calculating the cumulative bps for a movie. We could have an extra variable to calculate the instant bps instead: //Frame 2 - add as last line: lastByteCount = 0; //Frame 3 - change last line to: bps = Math.floor((actBytes-lastByteCount) * 1000 / (getTimer() - starttime)); //and switch last 2 statements (to give more accurate estimation :) ) //Frame 4 - add as first two lines: starttime = getTimer(); lastByteCount = eval(movietarget).getBytesLoaded() || 0; I am not sure whether that is a good idea or not... Hmm, I think I\'m going to try all this out :) Thanks for the inspiration! That\'s great stuff. Tim.
MARIAM Date: 27/03/2002
the loading can be done but how does one start the next loaded movie from the first movie. the subsequent movies will have a stop command at the beginning, so how does one go beyond the first frame in the subsequent movies.
Fox Date: 19/03/2003
I am running into the same problem as Mariam. I want the loaded movie to start playing, but: myTarget.Play(); //myTraget is the placeholder blank MC //the loaded external swf has a stop action in Frame 1 does not work. So how do I address the loaded external swf?
blah Date: 01/10/2003
Does this really work? It crashes Flash MX when I hit ctrl+enter.
mu Date: 29/12/2003
This SO doesn't work!! - Do you have an online working version or FLA to prove me wrong? :o)
Notice Date: 12/03/2004
This doesn't work.
APS Date: 19/08/2004
I think the problem here is the declaration of actMovieIdx in frame 1 and the incrementing in frame 2. In Flash the first item in an array is numbered 0, not 1. In your code you set actMovieIdx to 0 then increment it to 1 and 2 in the 2nd frame. Therefore when you are calling: moviename = moviearray[actMovieIdx++]; movietarget = moviearray[actMovieIdx++]; You are actually asking for: moviename = moviearray[1] = "target1" movietarget = moviearray[2] = "movie2.swf" I think the simple fix is to set actMovieIdx = -1 in the first frame but I haven't tested yet . . .
mw Date: 27/08/2004
Hmmm, when viewing the bandwidth profiler for this preload scheme, the playhead never moves beyond frame 3. Have others experienced this as well?
Add comment
Home