# MovieClip preloader

**URL:** https://forum.kirupa.com/t/movieclip-preloader/58855
**Category:** flash
**Created:** [July 26, 2004, 6:07pm UTC](https://forum.kirupa.com/t/movieclip-preloader/58855 "2004-07-26T18:07:52Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sintax](https://avatars.discourse-cdn.com/v4/letter/s/b9e5f3/32.png) [@sintax](https://forum.kirupa.com/u/sintax)
#### Post date: [July 26, 2004, 6:07pm UTC](https://forum.kirupa.com/t/movieclip-preloader/58855/1 "2004-07-26T18:07:52Z")

</div>

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](http://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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 26, 2004, 6:18pm UTC](https://forum.kirupa.com/t/movieclip-preloader/58855/2 "2004-07-26T18:18:37Z")

</div>

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](http://www.actionscript.org/tutorials/intermediate/MovieClipLoader_in_Flash_MX_2004/index.shtml)

–EP

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 26, 2004, 6:33pm UTC](https://forum.kirupa.com/t/movieclip-preloader/58855/3 "2004-07-26T18:33:15Z")

</div>

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… 😉

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [July 26, 2004, 8:46pm UTC](https://forum.kirupa.com/t/movieclip-preloader/58855/4 "2004-07-26T20:46:13Z")

</div>

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/](http://www.earfocus.com/debie/preview/)
