开发者

Why would bytesTotal increase in a AS3 preloader?

I'm creating a custom preloader for a Flex app and have noticed the following behavior: when loading, the progress bar goes to 100%, then down then back up, 开发者_运维问答and so on until the app is finished loading.

When I put a trace in the dowloadprogress listener, I see that while the app is loading, both bytesLoaded and bytesTotal increase, but not necessarily at the same time.

Code:

private function onDownloadProgress(event:ProgressEvent):void {
        var loaded:int = event.bytesLoaded;
        var total:int = event.bytesTotal;
        trace(event.target,loaded,total);
        _starfield.progress = loaded/total;
    }

Output:

[object Preloader] 134276 134276
[object Preloader] 265348 285007
[object Preloader] 285007 285007
[object Preloader] 678223 1322116
[object Preloader] 809295 1322116
[object Preloader] 1322116 1322116
[object Preloader] 1322116 1322116
[object Preloader] 1387652 1584342
[object Preloader] 1791882 1791882
[object Preloader] 2293133 2293133
[object Preloader] 2362938 2362938
[object Preloader] 2362938 2362938
[object Preloader] 2362938 2362938

Why does bytesTotal change during load?


As runtime shared libraries are started to be downloaded, the total can increase. You can learn a little more about it by reading the Preloader source code.

sdk\frameworks\projects\framework\src\mx\preloaders\Preloader.as

Here are some links to custom preloader samples that handle RSL's better than the default.

http://coding.bhirschmann.de/2008/03/20/preloader-for-flex-with-rsl-support/

http://www.leavethatthingalone.com/blog/index.cfm/2009/11/11/Flex4CustomPreloader


or another way would be to break a preloader into 6 stages, with a preloader loading each component and running from 0 to 100%, then incrementing a number or "parts" loaded and displaying that on screen too

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜