# MovieClip loader code

**URL:** <https://forum.kirupa.com/t/movieclip-loader-code/185754>\
**Category:** flash\
**Created:** [April 16, 2006, 4:32am UTC](https://forum.kirupa.com/t/movieclip-loader-code/185754 "2006-04-16T04:32:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![CayoHueso](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@CayoHueso](https://forum.kirupa.com/u/CayoHueso)\
**Post date:** [April 16, 2006, 4:32am UTC](https://forum.kirupa.com/t/movieclip-loader-code/185754/1 "2006-04-16T04:32:41Z")

</div>

Hi everbody,

I created a simple loader and converted it to a component.  
I can place it in a timeline, and in the actions layer write this code:

```auto

this.onMouseUp=function(){
loader_mc.the_mcl.loadClip("image.jpg", loader_mc._parent.holder_mc);
}

```

But if I try to do the same without the onMouseUp, as below, it does not work:

```auto

loader_mc.the_mcl.loadClip("image.jpg", loader_mc._parent.holder_mc);

```

I am using a MovieClipLoader object inside the loader.

Could anyone please help me figuring out what I amsoing wrong?  
Thanks

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 16, 2006, 5:04am UTC](https://forum.kirupa.com/t/movieclip-loader-code/185754/2 "2006-04-16T05:04:17Z")

</div>

The code in your component executes after that in your root timeline unless you use:  
[LIST=a]  
[_]a compiler directive (#initclip and #endinitclip) to have the code compiled before the movie starts  
[_]an AS2 class which is exported before the first frame by default[/LIST]So my question is, have you used one of the above methods?

---

<div class="post-metadata">

**Author:** ![CayoHueso](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@CayoHueso](https://forum.kirupa.com/u/CayoHueso)\
**Post date:** [April 16, 2006, 5:09am UTC](https://forum.kirupa.com/t/movieclip-loader-code/185754/3 "2006-04-16T05:09:24Z")

</div>

I don’t know how to use any of those ways…  
Do you know of any tutorial on how to do it?  
Thanks,

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 16, 2006, 5:17am UTC](https://forum.kirupa.com/t/movieclip-loader-code/185754/4 "2006-04-16T05:17:22Z")

</div>

Here are some tutorials, but since you don’t know what either of those methods are I’m assuming that maybe you haven’t set up your component in the way where they would work/be needed. Maybe you should post your FLA.  
[http://www.kirupa.com/developer/oop/index.htm](http://www.kirupa.com/developer/oop/index.htm)  
[http://www.kirupa.com/developer/oop2/AS2OOPindex.htm](http://www.kirupa.com/developer/oop2/AS2OOPindex.htm)

---

<div class="post-metadata">

**Author:** ![CayoHueso](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@CayoHueso](https://forum.kirupa.com/u/CayoHueso)\
**Post date:** [April 16, 2006, 5:44am UTC](https://forum.kirupa.com/t/movieclip-loader-code/185754/5 "2006-04-16T05:44:05Z")

</div>

Here is the link to the FLA (Flash 8):

[http://www.dyangochavez.com/downloads/loader\_test.fla](http://www.dyangochavez.com/downloads/loader_test.fla)

Thanks

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 16, 2006, 6:02am UTC](https://forum.kirupa.com/t/movieclip-loader-code/185754/6 "2006-04-16T06:02:38Z")

</div>

Unfortunately you component isn’t object-oriented because it isn’t structured around a MovieClip subclass so there is nothing you can really do except wait a frame for the code to be executed _ **OR** _ read those tutorials I posted and start OOP.

Here’s the quick fix which is actually very un-OO but gets the job done and allows you to read those tutorials fix it up yourself - it also allows me to do less work :hugegrin:

```auto
#initclip
LoaderClass = function () {
 this.the_mcl = new MovieClipLoader();
 this.the_listener = new Object();
 the_mcl.addListener(the_listener);
 the_listener.onLoadError = function(mc) {
  percent_txt.text = "Error";
 };
 //
 the_listener.onLoadProgress = function(mc, loadedBytes, totalBytes) {
  var nPercent:Number = Math.round((loadedBytes / totalBytes) * 100);
  percentBar_mc._width = nPercent;
  percent_txt.text = nPercent + "%";
 };
 //
 the_listener.onLoadStart = function(mc) {
  mc._alpha = 0;
 };
 //
 the_listener.onLoadComplete = function(mc) {
  showLoadedInt = setInterval(showLoaded, 50, mc);
 };
};
LoaderClass.prototype = new MovieClip();
Object.registerClass("tabs_loader6", LoaderClass);
LoaderClass.prototype.showLoaded = function(mc) {
 trace("cojones");
 mc._alpha += 10;
 _root.loader_mc._alpha -= 10;
 if (mc._alpha >= 100) {
  mc._alpha = 100;
  clearInterval(showLoadedInt);
  message_txt.text = "";
 }
 updateAfterEvent();
};
#endinitclip

```

---

<div class="post-metadata">

**Author:** ![CayoHueso](https://avatars.discourse-cdn.com/v4/letter/c/8e8cbc/32.png) [@CayoHueso](https://forum.kirupa.com/u/CayoHueso)\
**Post date:** [April 16, 2006, 6:13am UTC](https://forum.kirupa.com/t/movieclip-loader-code/185754/7 "2006-04-16T06:13:11Z")

</div>

Wow, thanks a lot, I will study those tutorials. I am still learning…
