开发者

Loader for functions?

I am attempting to monitor the progress of an image scroller I've built and all of the images (thumbs) load separately. W开发者_高级运维hat 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


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜