elamothe,
[quoted text, click to view] > Well, I'm basically doing the same thing you mention.
Let's step through it.
[quoted text, click to view] > PercentLoaded = _root.getBytesLoaded()/_root.getBytesTotal()*100;
> RoundLoaded = int(_root.getBytesLoaded()/_root.getBytesTotal()*100);
Okay, two variables representing a percentage of the loaded file. By
the way, to get your rounded, you could simply put ...
RoundLoaded = int(PercentLoaded);
.... since PercentLoaded equals the same thing anyway. For what it's worth,
int was deprecated with Flash 5 in favor of Math.round() ...
RoundLoaded = Math.round(PercentLoaded);
[quoted text, click to view] > if (MovieIsLoaded == 1) {
> gotoAndPlay('main',1)
> }
So now, if the variable MovieIsLoaded equals the number 1, goto and play
frame 1 of scene "main." So far, this variable isn't 1; in fact, it hasn't
been set yet, so the script continues ...
[quoted text, click to view] > else {
> if (PercentLoaded != 100) {
> _root.mc_needle.gotoAndStop(RoundLoaded);
> //If movie is not loaded, goto the frame "loaded"
> }
If PercentLoaded is not 100, do the animation, otherwise ...
[quoted text, click to view] > else {
> MovieIsLoaded = 1;
> gotoAndPlay(3);
> // Frame 3 is the "out" animation of the preloader
> }
> }
.... create and set MovieIsLoaded to 1, then goto and play frame 3.
The above sequence is re-initialized every time you hit refresh. So
imagine, when the browser refreshes, the variable MovieIsLoaded disappears,
which naturally means that first if() statement will never be true when the
movie is first loaded.
[quoted text, click to view] > How would you suggest writing it?
What I suggested earlier was to use if() to check getBytesLoaded()
against getBytesTotal() before anything else ... that *will* be different
for an already-cached SWF. See the difference?
I don't know the ins and outs of how your preloader is set up, but
here's a suggestion. If this doesn't copy/paste and simply work for you,
it's because I'm stabbing in the dark (since I don't have your FLA in front
of me).
More important than my code sample here is that you understand the
concept. Concept is key, because once you learn the code, you'll be able to
derive your own solutions. :)
Frame 1 script simply checks if getBytesLoaded() is greater than zero
AND is greater than or equal to getBytesTotal(). If that is true, the SWF
is obviously loaded, so go straight to the "main" scene, frame 1. If it's
not true, then the playback head will continue to ...
Frame 2 script sets a variable PercentLoaded to getBytesLoaded() divided
by getBytesTotal times 100. If that number is less than 100, the SWF
obviously isn't yet loaded, so send the mc_needle movie clip to a rounded
version of the number given. Once it does that, the playhead will continue
to frame 3, which simply sends the playhead back to frame 2. The process
will repeat until PercentLoaded is no longer less than 100, at which point
the playhead is sent to frame 4, which is where your "out" animation occurs.
// Frame 1
// This part skips the preloader animation
// if the SWF is already cached
if (_root.getBytesLoaded() > 0 && _root.getBytesLoaded() >=
_root.getBytesTotal()) {
gotoAndPlay("main", 1);
}
// Frame 2
PercentLoaded = _root.getBytesLoaded() / _root.getBytesTotal() * 100;
if (PercentLoaded < 100) {
_root.mc_needle.gotoAndStop(Math.round(PercentLoaded));
} else {
_root.gotoAndPlay(4);
// This line skips past the loop on frame 3 when loaded
// (change your "out" animation to frame 4)
}
// Frame 3
_root.gotoAndPlay(2);
David
stiller (at) quip (dot) net
"Luck is the residue of good design."