|
BulkLoader has very flexible ways to report the status of loading for it's items. By bytes / percentageThe most straight forward way is to use the amount of bytes loaded. Each BulkProgressEvent has the following properties that indicate progress by bytes: - bytesLoaded -> (int) The number of bytes loaded, a sum of all items.
- bytesTotal -> (int) The number of bytes loaded, a sum of all items. bytesTotal will be 0 until all items have begun loading.
- bytesTotalCurrent -> (int) The number of bytes loaded, a sum of all items.
- percentLoaded -> (Number) The ratio ( 0 -> 1) of bytesLoaded / bytesTotal.
While checking progress by bytes is the most accurate way, it can present problems. BulkLoader will use a pooling mechanism so the number of open connections don't exceed a certain value. Now, suppose you are using 5 connections and downloading 20 items. The bytesTotal cannot be determined until all 20 items have begun loading, and at least 15 items are already loaded. This means that the percentLoaded will be 0 almost until all items are loaded, and then it will jump abruptly. Worse, each time a new connection is open, the bytesTotal would jump around (it would add the bytesTotal for the new item). To mitigate this issue, bytesTotal will remain 0 until all file sizes are known. If you wish to know the sum of know total bytes use bytesTotalCurrent. So while being very accurate, using bytesTotal is not recommended unless the number of items is small. When loading a larger number of items, the two methods below are better alternatives. By ratioThe ratio count is a good way to track a large number of items. Each BulkProgressEvent has the following properties that help checking the ratio status: - itemsLoaded -> (int) the number of items loaded.
- itemsTotal -> (int) the number of all items to load.
- ratioLoaded -> (Number) A helper, a number between 0 and 1 that indicates itemsLoaded / itemsTotal.
Counting by ratio will give you an indicator that is immediately available, no matter how many items there are to load. This is the best way to track loading status when you have a large number of items to load of roughly the same size, for example all 40 thumbnails of an image gallery. If you have many items to load, and their sizes vary a lot, weighted progress is the way to go. By weightThis way is a bit more complex, but very useful. Lets imagine a very common scenario for loading: - a 1.2 mb swf file (main.swf)
- a 20 kb xml file (config.xml)
- a 20 kb xml file (strings.xml)
- a 300 kb mp3 file(soundtrack.mp3)
- a 120 kb background file (bg.jpg)
- 20 jpeg thumbnails of around 10 kb.
If you use progress by bytes, your progress count will be zero for a long time, than jump to almost complete at the end. If you use a ratio count, the items that are very large will skew the results. In this case we are loading 25 items. By ratio, each item corresponds to 4%. But the main.swf file is pretty large and the progress status will seem to be frozen while it's loading, since while it 4% by ratio, it's roughly 66% of the total bytes we must load. The solution here is to give BulkLoader a hint of how large the files are. This way, BulkLoader will calculate a proportional status, with no sudden jumps or freezes, but it requires a bit of planning. In our example, we can give weights based on each items size (at leats roughly) - main.swf -> 1200
- config -> 20
...
When adding each item, we give this hint as a "weight" option: bulkInstance.add("main.swf", {weight:1200});
bulkInstance.add("config.xml", {weight:20});
bulkInstance.add("strings.swf", {weight:20});
bulkInstance.add("soundtrack.mp3", {weight:300});
bulkInstance.add("background.jpg", {weight:200});
for each (thumb in thumbs){
bulkInstance.add(thumb, {weight:20});
}Now you can track a reasonable estimate of loading progress. Using the following properties of the BulkProgressEvent object: - weightPercent -> (Number) A number between 0 and 1 that indicates progress regarding weights.
This is the smoother way to track progress for a large number of items when their sizes vary greatly. A few things to keep in mind: - What matters is the proportion of weights, not an absolut number. On the example above you could establish that each weight would correspond to 20kb, so each thumb would have a weight of 1, the background a weight of 10, the main.swf a weigth of 60 and so forth.
- Items have a default weigth of 1, so if you don't set their weights the weightPercent will be the same as the ratioLoaded.
|
Hey, I'm having trouble using the 'ratioLoaded' property. It returns undefined property error for BulkLoader?.
Another thing I noticed is that in your 'API Documentation', that comes with the download, the name of the property is 'loadedRatio' and in the actual .as class file, the name of the property is 'loaded Ratio'. I'm sure it's just a typo but when I use the 'loadedRatio' property it allways returns zero. The only solution I could come up with is to raise my open connections but I had to put it up to something ridiculous (30).
Seeing as your weight solutions won't work for my project I was hoping you could give me some advice. I love this class by the way I think you've done a great job.
-Mauro
Hi Mauro.
I guess that there a couple of issues to be understood here.
The "loadedRatio" you are talking about is a property of a BulkProgressEvent?, beign fetched from a :
<bulkLoader>.addEventListener(BulkLoader.PROGRESS, onProgress); function onProgress( evt : BulkProgressEvent) :void{ trace(evt.loadedRatio); }correct? If so, I can't pinpoint what the issue with you code is.
I am not sure where the 'loaded Ratio' property is, since spaces are not legal characters for identifiers, nor why raising the number of open connections should do any difference.
As a side note, I've opened a discussion list at google groups: http://groups.google.com/group/bulkloader-users
It's easier to keep track of discussions over there, and it's all at the same place, so it helps to make the knowledge public. If you are still having problems, drop a line with more information at the discussion list and we'll do our best to help.
Cheers Arthur
What else dictates how many concurrent connections one can have open? Is it a "feature" of the Flash player?
In my project I have a need to download 5 images simultaneously. If i watch the requests for the image resources in a packet sniffer tool such as Charles, I can see that the actual amount of physical http requests being made varies. Sometimes two images are requested at the same time, other times 4. However, the numConnections parameter of the BulkLoader? class appears to have no influence on this (except perhaps to restrict the number of simultaneous downloads). This makes the process of showing an accurate download percentage figure nigh-on impossible without jumps in the value. It is, in effect, no different from firing off multiple Loader() calls.
Also, whilst on the subject (and perhaps because of the above), using the weighting option to report download status also appears to jump depending upon how many of the total amount of connections are open. And the ratio method on my system traces out as having itemsLoaded = 0 (always) and totalItems as a decreasing figure. So this method is also ruled out unfortunately.
Any comments?
Cheers