MovieClip preloader

Hi there,

I’ve searched for hours and hours, but I haven’t found an answer to my preloader question. And I’m sorry if it has been asked before…

How do you make a preloader for/with the MovieClipLoader?

I have created a MovieClipLoader and a listener object for it
var content_mcl:MovieClipLoader = new MovieClipLoader();
var loadingListener:Object = new Object();

Now I want to make a preloaderbar so the user gets informed of the status of the download, but how should I do this?

I found this on the forum:
//Assuming that your code was in the same timeline as _root
//hint: never use _root, use a relative reference
Object.rootMain = this;
onEnterFrame = function(){
percent = Object.rootMain.calcPercent();
Object.rootMain.loadBar.proc.text = percent;
if(percent >= 100){
delete onEnterFrame;
calcPercent:Number = function(){
var loaded = Object.rootMain.my_mc1.getBytesLoaded();
var total = Object.rootMain.my_mc1.getBytesTotal();
// sometimes total will be 0 if this check is made too soon,
// if it is, set it to an arbitrary value to make sure you don’t
// get a false indication that percent = 100
if(total <= 1) total = 100;
return Math.ceil(loaded/total);

But I can’t get it to work… Can anyone provide me with some code that does work?

Thanx in advance…

You’ve probably seen this already, but this page has some info and a download file.


Yeah, I’ve read it, and it hasn’t made me any wiser…

Thnx anyway, but I’m still hoping for someone to come along with a more practical solution… :wink:

So after some experimenting I figured it out myself (and it seems to work). But this code can’t (as it seems) be tested locally, so only from an online environment…

Here’s the code for those with similar problems:

//declare variables
var content_mcl:MovieClipLoader = new MovieClipLoader();
var loadingListener:Object = new Object();

//add listener object to MovieClipLoader
preloader_mc._visible = true;

loadingListener.onLoadProgress = function (target_mc, loadedBytes, totalBytes) {
var preloadPercent:Number = Math.round((loadedBytes/totalBytes)*100);
preloader_mc.onEnterFrame = function():Void {
this.preloaderBar_mc._width = preloadPercent;

loadingListener.onLoadComplete = function(target_mc) {
preloader_mc._visible = false;

content_mcl.loadClip(“algemeen.swf”, _root.content_mc);

Result can be seen here: