Tuesday, May 09, 2006

Preloading

To prevent all of the classes from loading in frame 1 (which causes an annoying blank screen for a long time before the preloader appears):
-I set them to load in a later frame (8).
-Movieclips in the library that have Classes attached to them need to have the "export in first frame" checkbox unchecked for this to work.
-For the classes to load there needs to be at least one instance on the stage somewhere in a timeline or the Class won't
load. For example, in the leaf game there are leaves that are pulled dynamically out of the library that have the "Leaf" class attached. These leaves weren't working until I realized that there was no instance of a leaf anywhere in the movie. I created an instance in "_root.leafHost.leafInit" and the leaves started working becuase they had been instantiated
by this new clip.
To preload sounds the same principles apply. There needs to be a frame with a sound attached
for attached sounds to work.
Here is some preloader code:

this.onEnterFrame = function() {
if (_framesloaded == _totalframes) {
delete this.onEnterFrame;
gotoAndStop("intro");
} else {
theProgress = "Loading "+(Math.floor(this.getBytesLoaded()/1000))+"K of "+(Math.floor(this.getBytesTotal()/1000))+"K";
preloadBar._width = (241*this.getBytesLoaded())/this.getBytesTotal();
}
};

Here is another preloader:

this.onEnterFrame = function() {
//trace("...");
preloader_mc.loaderText.text = "LOADING "+Math.floor(this.getBytesLoaded()*.001)+"K OF "+Math.floor(this.getBytesTotal()*.001)+"K";
preloader_mc.loaderBar._width=(preloader_mc.loaderBG._width*this.getBytesLoaded())/this.getBytesTotal()
if (this.getBytesLoaded() == this.getBytesTotal()) {
delete this.onEnterFrame;
gotoAndStop("titlescreen");
}
};

1 comment:

Albert said...

Hey Matt, I know your not active with on this blog anymore, but cheers for your tip that help me to avoid the dreaded blank screen that kills my pre-loader!

I spend 3 months looking for solutions on the net and tonight I your comment help heaps:
"To preload sounds the same principles apply. There needs to be a frame with a sound attached
for attached sounds to work."

Here in action:
http://www.awarsing.com/peaktrain

Thanks again!