# Help with MovieClipLoader

**URL:** <https://forum.kirupa.com/t/help-with-moviecliploader/251463>\
**Category:** flash\
**Created:** [February 8, 2008, 6:59pm UTC](https://forum.kirupa.com/t/help-with-moviecliploader/251463 "2008-02-08T18:59:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rooterman42](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@rooterman42](https://forum.kirupa.com/u/rooterman42)\
**Post date:** [February 8, 2008, 6:59pm UTC](https://forum.kirupa.com/t/help-with-moviecliploader/251463/1 "2008-02-08T18:59:26Z")

</div>

Hello,

I’m having a problem with MovieClipLoader loading multiple (3 jpg) files, and then starting my movie only after all three are loaded first. My movie has two frames, the first frame has the MovieClipLoader code, and the second frame is the actual movie playing. Problem is, my movie starts playing regardless of which jpg is loaded, so as soon as any one jpg finished loading, it starts playing frame two. I need to make sure it only starts after ALL three movies are fully loaded. Please help, newbie!

//Code on frame one:

stop();

// Set image to use:  
var image:String = “abl”;

bar.\_visible = false;  
border.\_visible = false;

// Create the image holders  
this.createEmptyMovieClip(“holder1”,1);  
this.createEmptyMovieClip(“holder2”,2);  
this.createEmptyMovieClip(“holder3”,3);

// \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
// Bandwidth Detector  
/\*  
Downloads a hidden test image from a predefined URL  
and determines client bandwidth based on how  
quickly the image is downloaded. Test image must  
be ~12k in filesize (smaller filesizes result in inaccurate  
detections on fast connections). Image is not cached due  
to random string added to URL.

“Test” variable in calc\_bandwidth(); is bandwidth value.  
(~300kbps cable/DSL, ~20kbps dialup)

The text field on the stage can be safely removed.

\*/  
// \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

// container for image  
this.createEmptyMovieClip(“imageMovieClip”,999);

// image loader object  
var testImage:MovieClipLoader = new MovieClipLoader();  
var testListener:Object = new Object();

// timer during image loading  
testListener.onLoadStart = function(targetMovieClip:MovieClip):Void {  
startTime = getTimer();  
};

// handle image loading  
testListener.onLoadProgress = function(targetMovieClip:MovieClip, numBytesLoaded:Number, numBytesTotal:Number):Void {  
var imageLoaded:Number = Math.ceil(100\*(numBytesLoaded/numBytesTotal));  
datasize = numBytesTotal;  
if (imageLoaded == 100) {  
endTime = getTimer();  
calc\_bandwidth();  
}  
};

// kbps conversion  
function calc\_bandwidth() {  
var offsetMilliseconds = endTime-startTime;  
var offsetSeconds = offsetMilliseconds/1000;  
var bits = datasize_8;  
var kbits = bits/1024;  
var bandwidth:Number = kbits/offsetSeconds;  
bandwidth = (bandwidth_(.93));  
test = Math.round(bandwidth)+“kbps”;  
// this is where you can put the if statement  
// test = bandwidth  
if (bandwidth\<57) {  
trace("bandwidth \< 57: "+bandwidth);  
//trace(“load jpg”);  
loadMovie(“images/”+image+“1.jpg”, holder1);  
} else {  
trace("bandwidth \> 57: "+bandwidth);

// Preloader

my\_mc = new MovieClipLoader();  
preload = new Object();  
my\_mc.addListener(preload);  
preload.onLoadStart = function(targetMC) {  
trace("started loading "+targetMC);  
holder1.\_alpha = 0;  
holder2.\_alpha = 0;  
holder3.\_alpha = 0;  
bar.\_visible = true;  
border.\_visible = true;  
pText.\_visible = true;  
};  
preload.onLoadProgress = function(targetMC, lBytes, tBytes) {  
bar.\_width = (lBytes/tBytes)\*100;  
pText.text = “% “+Math.round((lBytes/tBytes)\*100);  
};  
preload.onLoadComplete = function(targetMC) {  
trace(targetMC+” finished”);  
gotoAndStop(2);  
};

// Set up animation:

// Load images into the holders  
// this.onEnterFrame = function() {  
my\_mc.loadClip(“images/”+image+“1.jpg”, “holder1”);  
my\_mc.loadClip(“images/”+image+“2.jpg”, “holder2”);  
my\_mc.loadClip(“images/”+image+“3.jpg”, “holder3”);  
if (this.holder1.\_width\>0) {  
delete this.onEnterFrame;  
}  
}  
};

// load the test image and prevent it from being cached  
testImage.addListener(testListener);  
testImage.loadClip("[http://www.dquinn.net/home/im/layout/header.gif"+"?"+new](http://www.dquinn.net/home/im/layout/header.gif%22+%22?%22+new) Date().getTime(),imageMovieClip);

// hide image while it’s loading  
imageMovieClip.\_alpha = 0;

// End bandwidth detector code

// Code on Frame 2:

stop();

// Start actual animation

// Import Tween/Easing classes  
import mx.transitions.Tween;  
import mx.transitions.easing.\*;

// Set fade length in seconds:  
var fadeTime:Number = 2;  
// Initialize start time:  
var imageTimeInit:Number = 0000;  
// Set length of time between each fade:  
var imageTimeInterval:Number = +4000;  
// Set total play time:  
var animationLength:Number = 600000;

// holder 1  
setTimeout(function () {  
var myTween:Object = new Tween(holder1, “\_alpha”, Strong.easeOut, 0, 100, fadeTime, true);  
},imageTimeInit);

// holder2  
setTimeout(function () {  
var myTween:Object = new Tween(holder2, “\_alpha”, Strong.easeOut, 0, 100, fadeTime, true);  
var myTween:Object = new Tween(holder1, “\_alpha”, Strong.easeOut, 100, 0, fadeTime, true);  
},imageTimeInit=imageTimeInit+imageTimeInterval);

// holder3  
setTimeout(function () {  
var myTween:Object = new Tween(holder3, “\_alpha”, Strong.easeOut, 0, 100, fadeTime, true);  
var myTween:Object = new Tween(holder2, “\_alpha”, Strong.easeOut, 100, 0, fadeTime, true);  
},imageTimeInit=imageTimeInit+imageTimeInterval);

// start looping the animation:  
// holder3 fade back to holder1  
for (imageTimeInit; imageTimeInit\<animationLength; ) {  
setTimeout(function () {  
var myTween:Object = new Tween(holder3, “\_alpha”, Strong.easeOut, 100, 0, fadeTime, true);  
var myTween:Object = new Tween(holder1, “\_alpha”, Strong.easeOut, 0, 100, fadeTime, true);  
},imageTimeInit=imageTimeInit+imageTimeInterval);  
//trace(i);

```
// holder1 fade to holder2
setTimeout(function () {
var myTween:Object = new Tween(holder2, "_alpha", Strong.easeOut, 0, 100, fadeTime, true);
var myTween:Object = new Tween(holder1, "_alpha", Strong.easeOut, 100, 0, fadeTime, true);
},imageTimeInit=imageTimeInit+imageTimeInterval);
//trace(i);

// holder2 fade to holder3, then go back to start of loop              
setTimeout(function () {
var myTween:Object = new Tween(holder3, "_alpha", Strong.easeOut, 0, 100, fadeTime, true);
var myTween:Object = new Tween(holder2, "_alpha", Strong.easeOut, 100, 0, fadeTime, true);
},imageTimeInit=imageTimeInit+imageTimeInterval);
//trace(i);

```

}  
// End animation code
