Colin Moocks Preloader

Hey all, reading through Colin Moocks ASDG v2 come across a preloader which is


stop();
this.createEmptyMovieClip("loader",1);
this.loader.createEmptyMovieClip("totalBar",2);
this.loader.createEmptyMovieClip("loadedBar",3);
this.loader.createTextField("loadProgress_txt",4,80,10,200,20);
this.loader.loadedBar.lineStyle(5, 0xFF0000);
this.loader.totalBar.lineStyle(8, 0x000000);
this.loader.loadedBar.lineTo(250, 0);
this.loader.totalBar.lineTo(250, 0);

this.loader.onEnterFrame = function(){
	this.percentDone = Math.floor((this._parent.getBytesLoaded()
															   /this._parent.getBytesTotal())*100);
	this.loadProgress_txt.text= this.percentDone + "% complete";
	this.loadedBar._xscale = this.percentDone;
	this.loaded = this._parent._framesloaded;
	if(this.loaded > 0 && this.loaded == this._parent._totalframes){
		this._parent.gotoAndPlay("start");
		this.removeMovieClip();
	}
}

I pretty much understand whats going on, and its working fine, but as he mentions in the book in the as part has got me confused.


if(this.loaded > 0 && this.loaded == this._parent._totalframes){
}

He explain the following (extract from Colin Moocks ASDG v2)

"Notice that in our preloader examples we checked whether _framesloaded > 0 in addition to whether _framesloaded == _totalframes. This is necessary because when a movie is unloaded from a clip, that clip has a _totalframes of 0. Hence, if _framesloaded is 0 (as it might be on a very slow connection), the comparison _framesloaded == _totalframes can return true even when no frames have yet loaded. Our check prevents the movie from skipping ahead before the appopriate content had loaded. This precaution is not necessary with preloaders placed on the main timeline of loading .swf filesm because their _totalframes property is never 0.

Now does this mean that due to the preloader being created in a empty movie clip and by removing it at the end of the code, the _totalframes of it would return 0. So when next time the preloader is used on slow connection it would just thinks that it equals total frames.

Think of it this way…

An empty movie clip symbol has 0 _totalframes

So if you were to check if _framesloaded == _totalframes then it would return true because 0 frames loaded would be equal to 0 total frames.

So what Moock is trying to do here is check if there are MORE than 0 frames in the timeline that was loaded AND if the amount of frames loaded is equal to the total amount of the frames in the timeline. And that way Flash won’t get tricked by the empty clip having 0 _totalframes.

Does that help?

(i know i know, this is my first preloader question since retirement of preloader questions, but given the situation I don’t find it is a preloader question, but rather more of a “why is it like this” question)

hehe… thanks lost.

Thats what i thought it was , just wanted to make sure.
and i agree that its not a preloader questions … hehe… :smirk:

ok, reading it again. Wouldnt the preloader be looking for the _framesloaded and _totalframes of a content timeline (or external targeted swf timeline) not the preloader’s movieclip timeline. ??

based on

This precaution is not necessary with preloaders placed on the main timeline of loading .swf filesm because their _totalframes property is never 0

why is that so?

does it really matter if the preloaders movieclip equals 0 , since we are looking for the total frames of the _parent timeline not the preloades timeline. wouldnt the preloaders movieclip just run a loop?

:: sorry if these are stupid question, this is just got me a little bit puzzled.

when you load to an empty movie clip, the contents of that empty movie clip become the contents of your movie. And you can even target the contents of your movie by targeting the clip you loaded to. So loading a movie to an empty clip is essentially just dynamically loading a timeline into a movie clip that has no timeline.

ah ok i’m getting it now.

:: just tried the preloader with debugging speed of 28.8 kb without the code

this.loaded > 0

and it did , as Colin said, return true even when no frames have yet loaded.

But with it, it ran the preloader fine.

:: I must admit this book is pretty awesome!

thanks for the explanation lost. :thumb:

When you’re done with the book send it my way :wink: :wink:

Hehe… j/k

I really do want to buy a copy of that book though, I still have a lot to learn :x

you can never learn too much…

at one time, i was learning maya , 3dmax, xsi , flash , and dreamweaver, think my brain nearly blew up though. :!:

LOL, you can never learn too much, but you can try to learn too much at once.

I am currently at that problem. I am still learning AS, while still learning Javascript, and just beginning to tackle PHP/mySQL and I am going to be starting Java AND proce55ing soon :hangover: