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
[AS]
var content_mcl:MovieClipLoader = new MovieClipLoader();
var loadingListener:Object = new Object();
[/AS]

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 actionscript.org forum:
[AS]
//Assuming that your code was in the same timeline as _root
//hint: never use _root, use a relative reference
Object.rootMain = this;
my_mc1.load(“home.swf”);
onEnterFrame = function(){
percent = Object.rootMain.calcPercent();
Object.rootMain.loadBar.proc.text = percent;
Object.rootMain.loadBar.gotoAndStop(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);
};
[/AS]

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

Thanx in advance…
Sintax

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

http://www.actionscript.org/tutorials/intermediate/MovieClipLoader_in_Flash_MX_2004/index.shtml

–EP

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:

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

//add listener object to MovieClipLoader
content_mcl.addListener(loadingListener);
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) {
gotoAndPlay(“opening”);
preloader_mc._visible = false;
};

content_mcl.loadClip(“algemeen.swf”, _root.content_mc);
[/AS]

Result can be seen here:
http://www.earfocus.com/debie/preview/