Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preloading flashmovies = one step further

Status
Not open for further replies.

orbitph

Programmer
Feb 23, 2001
35
0
0
NL
Hey all,

got a problem, i know how to preload a movie but now the tricky part, creating a nice percent counter which indicates how much of the movie is loaded.

anyone got an example for me??

just doing fine with flash, wonderfull program >:):O>

greetz, if you have tips or comments send them to me. I am a human and humans could give wrong answer

Want see some flash?? visit or
 
Create a movieclip with a short animated sequence with an obvious begining and end. Place the movieclip in the first frame of the scene with the stop action assigned to the frame. on the moiveclip on clip event select enterframe then
if(_root._framesloaded=_root.totalframe){
_root.gotoAndPlay(2);
}else{
this.gotoAndStop(Math.floor((_root._framesloaded/_root._totalframes)*this.totalframes
 
An easy preloader!

3 frames in it's on scene, the first in the scene order.

Frame 1:
Blank keyframe with:

if (_root.getBytesLoaded() >= _root.getBytesTotal()) {
gotoAndPlay ("Scene 1", 1);
}

This frame is only to avoid seeing a Flash frame of this preloader, on subsequent visits to your site, that is after the first visit, and assuming your movie would still be in the user's cache.

Frame 2:
Keyframe with:

// Calculate loaded, total KBs and percent.
loaded = Math.round(getBytesLoaded() / 1024);
total = Math.round(getBytesTotal() / 1024);
percent = Math.round((loaded/total) * 100);
// Define 1 or more textfield(s)
bytesLoadedOutput = loaded;
bytesTotalOutput = total;
percentOutput = percent + "%";

if (_root.getBytesLoaded() >= _root.getBytesTotal()) {
gotoAndPlay ("Scene 1", 1);
}

Frame 3:
Keyframe with:

gotoAndPlay(2);

Now add another layer (or layers if needed) to create a loading message and/or your textfields.
Frame 1 should be kept blank, and the other layers only cover frames 2 & 3.

Using a combination of the 3 defined textfields, you can display something like:

LOADED (bytesLoadedOutput) OF (bytesTotalOutput) BYTES.

Or simply:

(percentOutput) LOADED.

Regards,
new.gif
 
Blast,
if(_root._framesloaded=_root.totalframe){

The above wouldn't obviously work, for 2 reasons...
And please explain how your script would display a % loaded?

Regards,
new.gif
 
that code is checking to see if all the frame of the movie are loaded, don't need to show the preloader otherwise. If the movie clip has a bar which movies from left to right say over 10 frame this code will move the frames of the bar clip along the timeline until it is fully loaded. I admit it is not 100% accurate in that some frames take longer to load then others but it is deffinatly close enough. I like it simply for the simplicity of the code.
 
Got ya!
But you haven't answered my questions!
Guess Orbitph will figure it out, if he decides to use it!

Regards,
new.gif
 

faq250-630

dave
dave@pinkzeppelin.com

^^^^^^^^^^^^^^^^^^^^^​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top