Groups | Blog | Home
all groups > flash actionscript > august 2005 >

flash actionscript : When I refresh, I don't want to see the preloader


David Stiller
8/11/2005 7:07:51 PM
elamothe,

[quoted text, click to view]

I don't know how you did your preloader, but a common way is to check
the _root's getBytesLoaded() against its getBytesTotal() and keep looping
until loaded bytes are equal to or greater than total bytes (in addition to
being greater than zero). If you have this loop happening on, say, frames 3
and 4 -- 4 simply says gotoAndPlay(3) and 3 has the bytes testing -- you
could precede that code (in frame 1 or 2) with a separate if statement.
Simply check if the _root's getBytesLoaded() value is greater than or equal
to its getBytesLoaded() value (and greater than zero). It's the same code
as your preloader (assuming you're using that approach) ... but in this
case, you'll send the playhead to frame 5 (or later), thus bypassing the
preloader animation.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

elamothe
8/11/2005 10:03:29 PM
I've got my preloader on a seperate scene, and it preloads just like I want it
to. The file itself is going as a banner for a forums site.

My problem is that whenever someone clicks on a thread, the banner at the top
will play the animation that is part of the preloader, and then play the main
animation that we want. I'm trying to find a way to get around the fact that
it'll play the preload "out" animation if it's already been loaded once
(because the visitor has already loaded the .swf into their cache).

I tried nesting the preloading IF statement into another IF statement that
sets a flag to '1' after everything is preloaded, and to check against that
flag, but apparently i'm not understanding something, or i'm doing something
wrong.

Can someone help me out?

If you want to see what I mean, look at the flash banner @
http://forums.neo240sx.ca and hit refresh. You'll see the "out" animation of
the preloader.
elamothe
8/12/2005 12:00:00 AM
Well, I'm basically doing the same thing you mention.

Here's my code on Frame 1 of my "preloader" scene.

---------

PercentLoaded = _root.getBytesLoaded()/_root.getBytesTotal()*100;
RoundLoaded = int(_root.getBytesLoaded()/_root.getBytesTotal()*100);
if (MovieIsLoaded == 1) {
gotoAndPlay('main',1)
}
else {
if (PercentLoaded != 100) {
_root.mc_needle.gotoAndStop(RoundLoaded);
//If movie is not loaded, goto the frame "loaded"
}
else {
MovieIsLoaded = 1;
gotoAndPlay(3);
// Frame 3 is the "out" animation of the preloader
}
}

------

How would you suggest writing it?

David Stiller
8/12/2005 5:56:57 PM
elamothe,

[quoted text, click to view]

Let's step through it.

[quoted text, click to view]

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]

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]

If PercentLoaded is not 100, do the animation, otherwise ...

[quoted text, click to view]

.... 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]

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."

AddThis Social Bookmark Button