all groups > flash actionscript > august 2005 >
You're in the

flash actionscript

group:

preloader and movie clip



preloader and movie clip dawndawg
8/6/2005 5:45:37 PM
flash actionscript: I have a preloader with some dynamic text and a movie clip. I want the movie
clip to play progressively as the whole movie loads. My dynamic text works,
but the "loading" movie clip just plays frame 10 (the last frame). The only
code in the movie clip is a stop; in frame 1. Here is my code for frame 1 of
the main movie.

stop();
myInterval = setInterval(preloader, 10);
function preloader() {
if (getBytesLoaded()>=getBytesTotal()) {
play();
clearInterval(myInterval);
}
percentLoaded.text = Math.round(getBytesLoaded()/getBytesTotal()*100)+"%";

loading.gotoAndStop(Math.round(getBytesLoaded()/getBytesTotal()*(_root.getBytesT
otal())));
}
Re: preloader and movie clip NSurveyor
8/6/2005 6:54:05 PM
The problem is simple. (I put the complete correct code in your other thread).
This is what's happening:

You want your loading movieclip to go to frame:

Math.round(getBytesLoaded()/getBytesTotal()*_root.getBytesTotal());

If you look at it, you'll see that dividing the bytesTotal and multiplying by
it, just cancels out. That means you are trying to send the playhead to
getBytesLoaded() frame, which is probably more than 1000. So, it tries to go to
Frame 1000, which does not exist, leaving it no choice but to go to the last
frame.

The fix:

The fraction of completion is getBytesLoaded()/getBytesTotal(); The total
number of frames is 10. So, you want to multiply the totalframes by the
fraction in order to find out of 10, how much is loaded. For example, if 10% is
loaded, aka .1. Then, you want to go to frame 1. If 20% is done, or .2 then you
go to 10. If 100% is done, or 1, then you want to go to 10. 10*.1 = 1; 10*.2 =
2 ... 10*1 = 10

I hope you get the idea. But, what happens if 15% is done, or .15. Multiply by
10 to get the framenumber... uh oh! What's frame 1.5? You need to round it. I
chose to use Math.ceil since if it says to go to frame .5, it won't try to go
to frame 0. However, Math.round may make the animation look smoother. Play
around with it. (Remember, look at your other thread)

AddThis Social Bookmark Button