views:

66

answers:

3

Hi all,

I am attempting to monitor the progress of an image scroller I've built and all of the images (thumbs) load separately. What would be the best way of figuring out what the total progress of the images that are loading?

I was thinking it would be cool to use a generic loader and apply it to a function such as

myScroller.loadImages();

But I haven't seen any examples of that. I did come across this thread:

but I'm not sure if it really addresses the issue I'm up against or not.

Thanks for any thoughts or expertise. jml

+1  A: 

the problem is that you only know the size of an image if you start loading it so there are three options i guess:

1) start loading each of the image and stop immediately after you get the size. the disadvantage is that you double the requests.

2) when you start to load the first image, multiply it's size with the number of images. disadvantage is that this is inprecise.

3) if you define the images somewhere outside your app for instance in an xml you could add some kind of filesize attribute and when you compile your app inject the sizes via some custom ant task into the xml.

i favour option 3.

maxmc
i like option 3 as well, but i had a question- i know nothing about apache work and i haven't verified that my site is actually running on an apache server. i saw this:http://stackoverflow.com/questions/312652/how-to-use-size-of-file-inside-ant-targetwhich looks promising... but i am creating the xml on the fly with a php script already... it looks at the directory and pulls out the filenames, populating the tags with some attributes. i'm not sure how i would integrate the two.
jml
like falomir already said, you have everything at hand with you php script. just compute the neccessary information in your php script and add it to your xml (on the fly of course)
maxmc
+1  A: 

Depending on the scale of your app you could look into the bulkloader library. It's not exactly lightweight, about 16kb I think, but if you're loading quite a few images then that shouldn't be too much of an impact. Check the site for detailed instructions but you do something like this:

private var $loader : Bulkloader = new BulkLoader( "ExampleLoader" );

private function startLoad() : void
{
    $loader.add( "image1.jpg", { id : "image1", type : "image" });
    $loader.add( "image2.jpg", { id : "image2", type : "image" });
    $loader.add( "image3.jpg", { id : "image3", type : "image" });

    $loader.addEventListener( BulkLoaderEvent.COMPLETE, loadComplete )
    $loader.start();
}

private function loadComplete( e : BulkLoader ) : void
{
    var thumbNail : ThumbNail = new ThumbNail( $loader.getBitmap( "image1" ) );
}

Not sure if that's exactly right but you should get the idea.

Rich

rlayte
+1  A: 

Hey there, I would lean towards the 3rd. option mentioned by maxmc. I'd have an XML with the info. of all the images I want to load (e.g. name, size, etc); this way I will know ahead how many images are going to be loaded, if I want to measure the overall progess based on the number of the remaining images, but also the total bytes I have to load in case I want to monitor the overall progress in terms of remaining bytes to load.

This XML of course could be created on demand; you just need to create a script that gets, from flash, the folder or location which you want to load images from, so it reads it, get the necessary info about the images and returns to flash the result as XML so it can proceed with the load images process.

falomir