Groups | Blog | Home
all groups > flash actionscript > march 2006 >

flash actionscript : MovieClipLoader within a FOR loop



JakeTheSnake3.0
3/9/2006 11:37:53 PM
Hello all, I've been browsing every time of forum possible and I have yet to
come across a solution to my problem. Here it is.

I have an swf.
Within the swf's library, I have a movie clip.
Within the main swf I use a FOR loop to attach the movie clip that is in the
library, and then I use MovieClipLoader() to load in the appropriate jpeg.
Everything loads just fine, except that I have no way of figuring out how to
monitor the downloads of all of the instances of the moviecliploader
class...Here's the FOR loop I was talking about.


// Let's say _global.sectionTotal was equal to 6...that would mean that this
FOR loop would run 6 times in an instant and then exit.


_global.sectionTotal = sectionTotal;
for (_global.count=1; _global.count<=_global.sectionTotal; _global.count++) {


// The next line is a variable declaration used for the purposed of being able
to use the . syntax reference to the appropriate attached movie clip.

s_loader = "small_loader"+_global.count;

// image_select_mc is a movie clip that is inside the main swf. It is the
movie clip where I am attaching all instances of the movie clip from within the
library. The movie clip from within the library is a small clip that will
house the dynamically loaded image.

image_select_mc.attachMovie("Small_Loader", "small_loader"+_global.count,
_global.count+5);

// image_select is basically what I talked about a few lines of code
above...it means that i'm currently referencing
image_select_mc.small_loader1...or image_select_mc.small_loader2...etc based on
the current iteration of this FOR loop.

image_select_mc.invis_text.text = _global.count;

// This if statement is simply for placement of the attached movie
clips...don't bother reading it.
if (_global.count>1) {
image_select_mc._x = ((_global.count-1)*58)+5;
} else {
image_select_mc._x = 5;
}
image_select_mc._y = -20;

// This is where the problem is! The objects being created actually work as
expected...like my_mcl is a moviecliploader object that gets created 6 times
and is named accordingly...my_mcl1...my_mcl2...etc. Everything loads just
fine, but I have no way of monitoring the download of all instances of my_mcl!
Any help would be appreciated!

var my_mcl = "my_mcl"+_global.count;
//trace(my_mcl);
my_mcl = new MovieClipLoader();
var myListener = "myListener"+_global.count;
//trace(myListener);
myListener = new Object();
my_mcl.addListener(myListener);

// This line of code loads the appropriate image for the appropriate attached
movie clip...ex) digital2small.jpg loads into the attached movie
small_loader2....digital3small.jpg loads into small_loader3...so on and so
forth.


my_mcl.loadClip("../fscommand/Images/small/"+_global.portsection+""+_global.c
ount+"small.jpg", "image_select_mc."+s_loader);

// Help!

myListener.onLoadComplete = function(my_mcl) {
trace("Completed");
};
}


Currently I have a static version (the images aren't loaded dynamically) on
the web. Click on Portfolio>sublink. to see what I am striving for.

http://dca.durhamc.on.ca/~mitchell/Portfolio

any comments about the site will be appreciated!
kglad
3/10/2006 3:52:57 AM
JakeTheSnake3.0
3/10/2006 4:34:15 AM
I want to have a composite preloader...I want to be able to gather the total
byte information of all 6 loading files, and the current # of bytes loaded from
each 6 loading files. If I can get that type of information in multiple
variables (there would be 12 in total - 6 for total bytes and another 6 for
bytes loaded), or variables put into an array, then I can simply add up the
total of all 6 of the total bytes information to get an _global.totalBytes
variable, and an _global.loadedBytes variable. That information would be
displayed via a preloader bar.
JakeTheSnake3.0
3/10/2006 3:25:05 PM
I have since changed my code, and now i'm passing the _global.count variable
through to a text field in the attached movie clip...as such, I am now loading
the image from within the attached movie clip. However no matter what I do, I
can't get it to work correctly...For now I have foregone the preloader and
simplified it for testing purposes. The main clip will play once all images
have been loaded...it for now, will not keep track of the download.


This is the code from within the attached movie clip. When I test the movie
with simulated download speed, it doesn't wait for the movie clips to load....I
think it's taking the current value of the empty movie clip (in which the image
is dynamically loaded) and determining if the main timeline has downloaded it's
size...which at the time is probably 4 bytes...and then continues onward...I
don't know how to fix this.

stop();
//
var myListener = new Object();
myListener.onLoadComplete = function(small_image_mc) {
_global.totalBytes++;
}
//
var my_mcl = new MovieClipLoader();
my_mcl.addListener(myListener);

my_mcl.loadClip("../fscommand/Images/small/"+_global.portsection+""+invis_text.t
ext+"small.jpg", small_image_mc);

kglad
3/10/2006 3:43:21 PM
if you have an array of your target movieclips you can use one loader and one
listener and maintain an array of the bytesloaded and bytestotal. using those
two arrays you can display what you want.



targetMCA=[target1,target2,...];
bytesLoadedA=[];
bytesTotalA=[];


myListener.onLoadProgress=function(targetMC,bl,bt){
for(var i=0;i<targetMCA.length;i++){
if(targetMC==targetMCA[i]){
bytesTotalA[i]=bt;
bytesLoadedA[i]=bl;
}
}
}
JakeTheSnake3.0
3/10/2006 4:41:15 PM
For now I just need to get this listener working. The listener is within the
attached movie clip itself, so I just need to properly work for the image that
is being loaded.

stop();
//
var myListener = new Object();
myListener.onLoadComplete = function(small_image_mc) {
_global.totalBytes++;
}
//
var my_mcl = new MovieClipLoader();
my_mcl.addListener(myListener);

my_mcl.loadClip("../fscommand/Images/small/"+_global.portsection+""+invis_text.t
ext+"small.jpg", small_image_mc);

// The above statement is the one that loads the image into the movie clip.
The myListener.onLoadComplete function just isn't working properly - it's
thinking that the movie clip is fully loaded when the image filesize is much
larger and couldn't possibly be done so quickly.
kglad
3/11/2006 5:02:19 AM
AddThis Social Bookmark Button