PDA

View Full Version : The MULTIPLE MC preloader,,, un answered :(


vibetribe
01-15-2006, 01:09 AM
This is the current AS i wrote for 25 empty MCs which need to preload 25 jpegs.... it works kinda sorta hit and miss,, is there any code more efficient? and reliable?

this.onEnterFrame = function() {
theLoading = (_root.mcSmall1.getBytesLoaded()+_root.mcSmall2.ge tBytesLoaded()+_root.mcSmall3.getBytesLoaded()+_ro ot.mcSmall4.getBytesLoaded()+_root.mcSmall5.getByt esLoaded()+_root.mcSmall6.getBytesLoaded()+_root.m cSmall7.getBytesLoaded()+_root.mcSmall8.getBytesLo aded()+_root.mcSmall9.getBytesLoaded()+_root.mcSma ll10.getBytesLoaded()+_root.mcSmall11.getBytesLoad ed()+_root.mcSmall12.getBytesLoaded()+_root.mcSmal l13.getBytesLoaded()+_root.mcSmall14.getBytesLoade d()+_root.mcSmall15.getBytesLoaded()+_root.mcSmall 16.getBytesLoaded()+_root.mcSmall17.getBytesLoaded ()+_root.mcSmall18.getBytesLoaded()+_root.mcSmall1 9.getBytesLoaded()+_root.mcSmall20.getBytesLoaded( )+_root.mcSmall21.getBytesLoaded()+_root.mcSmall22 .getBytesLoaded()+_root.mcSmall23.getBytesLoaded() +_root.mcSmall24.getBytesLoaded());
theLoaded = (_root.mcSmall1.getBytesTotal()+_root.mcSmall2.get BytesTotal()+_root.mcSmall3.getBytesTotal()+_root. mcSmall4.getBytesTotal()+_root.mcSmall5.getBytesTo tal()+_root.mcSmall6.getBytesTotal()+_root.mcSmall 7.getBytesTotal()+_root.mcSmall8.getBytesTotal()+_ root.mcSmall9.getBytesTotal()+_root.mcSmall10.getB ytesTotal()+_root.mcSmall11.getBytesTotal()+_root. mcSmall12.getBytesTotal()+_root.mcSmall13.getBytes Total()+_root.mcSmall14.getBytesTotal()+_root.mcSm all15.getBytesTotal()+_root.mcSmall16.getBytesTota l()+_root.mcSmall17.getBytesTotal()+_root.mcSmall1 8.getBytesTotal()+_root.mcSmall19.getBytesTotal()+ _root.mcSmall20.getBytesTotal()+_root.mcSmall21.ge tBytesTotal()+_root.mcSmall22.getBytesTotal()+_roo t.mcSmall23.getBytesTotal()+_root.mcSmall24.getByt esTotal());
percent = (theLoading/theLoaded)*100;
if (!isNan(percent)) {
if (percent == 0) {
percent_display = "";
} else {
percent_display = Math.ceil(percent)+"%";
}
if (percent>1) {
_root.mcLoadPane._visible = true;
}
_root.scrollclip._visible = false;
}
if (percent == 100) {
this.gotoAndStop(1);
_root.mcLoadPane._visible = false;
delete this.onEnterFrame;
percent_display = "";
_root.scrollclip._visible = true;
}
};
stop();

Many thanks in advance for those that can help,,, :)

avi

www.thedirectorscut.org

Flash Gordon
01-15-2006, 01:10 AM
dear heavens, no one can read that! Format it.

vibetribe
01-15-2006, 01:41 AM
could have swarn i did the (code) thing,, oh well,, there u have it :)

I also tried this,, which i believe would probably be a more forward thinking option,, but for some reason it doesnt work properly either,,, the mcScrollPane becomes invisible and all jpegs show except for 2,,, point is ,, if the code is working,, the mcScrollPane should not dissapear until ALL jpegs are loaded,,,

anyway ,, here is the other code i tried to do what i just described ,,,

//trace function
_root.scrollclip._visible = false;
_root.mcLoadPane._visible = true;
/************************************************** *******************/
//init
var myMCL = new MovieClipLoader();
/************************************************** *******************/
//callbacks
myMCL.onLoadStart = function(targetMC) {
var loadProgress = myMCL.getProgress(targetMC);
trace("The movieclip "+targetMC+" has started loading");
trace("Bytes loaded at start="+loadProgress.bytesLoaded);
trace("Total bytes loaded at start="+loadProgress.bytesTotal);
trace("____________________________________");
_root.scrollclip._visible = false;
_root.mcLoadPane._visible = true;
};
myMCL.onLoadProgress = function(targetMC, loadedBytes, totalBytes) {
trace("movie clip: "+targetMC);
trace("Bytes loaded at progress callback="+loadedBytes);
trace("Bytes total at progress callback="+totalBytes);
trace("____________________________________");
_root.scrollclip._visible = false;
_root.mcLoadPane._visible = true;
};
myMCL.onLoadComplete = function(targetMC) {
trace(targetMC+" has finished loading.");
var loadProgress = myMCL.getProgress(targetMC);
trace("Bytes loaded at end="+loadProgress.bytesLoaded);
trace("Bytes total at end="+loadProgress.bytesTotal);
trace("____________________________________");
_root.scrollclip._visible = false;
_root.mcLoadPane._visible = true;
};
myMCL.onLoadInit = function(targetMC) {
trace("Movie clip:"+targetMC+" is now initialized");
targetMC._width = 72;
targetMC._height = 90;
trace("____________________________________");
_root.scrollclip._visible = true;
_root.mcLoadPane._visible = false;
};
/************************************************** ******************/
//load the files in to their respective targets
myMCL.loadClip("dc_images/small1.jpg", "_root.scrollclip.movStrip1.mcSmall1");
myMCL.loadClip("dc_images/small2.jpg", "_root.scrollclip.movStrip1.mcSmall2");
myMCL.loadClip("dc_images/small3.jpg", "_root.scrollclip.movStrip1.mcSmall3");
myMCL.loadClip("dc_images/small4.jpg", "_root.scrollclip.movStrip1.mcSmall4");
myMCL.loadClip("dc_images/small5.jpg", "_root.scrollclip.movStrip1.mcSmall5");
myMCL.loadClip("dc_images/small6.jpg", "_root.scrollclip.movStrip1.mcSmall6");
myMCL.loadClip("dc_images/small7.jpg", "_root.scrollclip.movStrip1.mcSmall7");
myMCL.loadClip("dc_images/small8.jpg", "_root.scrollclip.movStrip1.mcSmall8");
myMCL.loadClip("dc_images/small9.jpg", "_root.scrollclip.movStrip1.mcSmall9");
myMCL.loadClip("dc_images/small10.jpg", "_root.scrollclip.movStrip1.mcSmall10");
myMCL.loadClip("dc_images/small11.jpg", "_root.scrollclip.movStrip1.mcSmall11");
myMCL.loadClip("dc_images/small12.jpg", "_root.scrollclip.movStrip1.mcSmall12");
myMCL.loadClip("dc_images/small13.jpg", "_root.scrollclip.movStrip1.mcSmall13");
myMCL.loadClip("dc_images/small14.jpg", "_root.scrollclip.movStrip1.mcSmall14");
myMCL.loadClip("dc_images/small15.jpg", "_root.scrollclip.movStrip1.mcSmall15");
myMCL.loadClip("dc_images/small16.jpg", "_root.scrollclip.movStrip1.mcSmall16");
myMCL.loadClip("dc_images/small17.jpg", "_root.scrollclip.movStrip1.mcSmall17");
myMCL.loadClip("dc_images/small18.jpg", "_root.scrollclip.movStrip1.mcSmall18");
myMCL.loadClip("dc_images/small19.jpg", "_root.scrollclip.movStrip1.mcSmall19");
myMCL.loadClip("dc_images/small20.jpg", "_root.scrollclip.movStrip1.mcSmall20");
myMCL.loadClip("dc_images/small1.jpg", "_root.scrollclip.movStrip1.mcSmall21");
myMCL.loadClip("dc_images/small2.jpg", "_root.scrollclip.movStrip1.mcSmall22");
myMCL.loadClip("dc_images/small3.jpg", "_root.scrollclip.movStrip1.mcSmall23");
myMCL.loadClip("dc_images/small4.jpg", "_root.scrollclip.movStrip1.mcSmall24");
myMCL.loadClip("dc_images/small5.jpg", "_root.scrollclip.movStrip1.mcSmall25");

vibetribe
01-15-2006, 09:14 PM
ok ,,, no one have any ideas???? how to make this A NONE SEQUENTIAL preloader,,, i need them all to load before anything happens,, ie,,,

no jpegs can be seen until the sum of ALL jpegs are loaded.

Anyone?????

Flash Gordon
01-15-2006, 09:27 PM
you first code looks alright to me ( a little funky in some places) but it look like it should work. However, that kind of preloaders never do, i have no idea why?

Oldnewbie????

vibetribe
01-15-2006, 11:26 PM
awwwww,,, after reading other posts on all the boards,, i think if this can be answered, alot of people would be very happy,,

its one thing to do multiple preloader for AS invoked mcs,, but another to apply it to MCs already on the timeline,,,

oldnewbie,, my old flashkit master,,, what say u ?

vibetribe
01-16-2006, 02:10 AM
I have an idea,,, can u do the following?

myMCL.onLoadInit = function(targetMC) {
//have some code to at "1" to a number var/object everytime onLoadInit is reached for a loaded jpeg.
};

for example
a jpeg completes loading, AS ads 1 to and object so when that object equals a certain number (eg, 25 for the 25 movie im loading), then whatever needs happening can happen ie, play this do that etc...

vibetribe
01-16-2006, 02:31 AM
SO VERY DAMN SIMPLE,,, I was staring,, and it just came to me , HOPE THIS HELPS EVERYONE ELSE :)



stop();
var counting = 0;
myMCL.onLoadInit = function(targetMC) {
counting = counting+1;
if (counting == 25) {//this is the crux of it ,,, simply put the amount of jpegs u are preloading here,,, and it will do everything when it has loaded that amount,, in this case, 25 jpegs YAY
play();//or whatever u want your movie to do next YAY AGAIN
}
trace(counting);//i just put this so u can see it counting, how glorious
}
myMCL.loadClip("dc_images/small1.jpg", "_root.mcSmall1");
myMCL.loadClip("dc_images/small2.jpg", "_root.mcSmall2");
//yadda yadda yadda
myMCL.loadClip("dc_images/small25.jpg", "_root.mcSmall25");

nfh
02-05-2006, 05:42 PM
SO VERY DAMN SIMPLE,,, I was staring,, and it just came to me , HOPE THIS HELPS EVERYONE ELSE :)



stop();
var counting = 0;
myMCL.onLoadInit = function(targetMC) {
counting = counting+1;
if (counting == 25) {//this is the crux of it ,,, simply put the amount of jpegs u are preloading here,,, and it will do everything when it has loaded that amount,, in this case, 25 jpegs YAY
play();//or whatever u want your movie to do next YAY AGAIN
}
trace(counting);//i just put this so u can see it counting, how glorious
}
myMCL.loadClip("dc_images/small1.jpg", "_root.mcSmall1");
myMCL.loadClip("dc_images/small2.jpg", "_root.mcSmall2");
//yadda yadda yadda
myMCL.loadClip("dc_images/small25.jpg", "_root.mcSmall25");

Does Flash/Actionscript have any semaphore mechanism that allows exclusive access to variables? For instance, in the (remote) case that two or more images (in your example) are loaded at the exact same time, the onLoadInit event is also generated at the same time. This means that the "couting" variable will have the same value on both event calls. This also means that in the end the "counting" variable could end up with a value smaller than 25. With an exclusive access mechanism the first event that gets the "counting" value would lock the variable so that it gets freed only after it increments the value and not before.

oldnewbie
02-05-2006, 07:04 PM
http://www.actionscript.org/tutorials/intermediate/MovieClipLoader_in_Flash_MX_2004/index.shtml