为什么 AS3 预加载器中的 bytesTotal 会增加?
我正在为 Flex 应用程序创建自定义预加载器,并注意到以下行为:加载时,进度条变为 100%,然后向下然后返回,依此类推,直到应用程序完成加载。
当我在 dowloadprogress 侦听器中进行跟踪时,我发现在加载应用程序时,bytesLoaded 和 bytesTotal 都会增加,但不一定同时增加。
代码:
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;
}
输出:
[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
为什么 bytesTotal 在加载过程中发生变化?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
随着运行时共享库开始下载,总数可能会增加。您可以通过阅读
Preloader
源代码了解更多信息。以下是一些自定义预加载器示例的链接,这些示例比默认值更好地处理 RSL。
http://coding.bhirschmann.de /2008/03/20/preloader-for-flex-with-rsl-support/
http://www.leavethatthingalone.com/blog/index.cfm/2009/11/11/Flex4CustomPreloader
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.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
或者另一种方法是将预加载器分为 6 个阶段,预加载器加载每个组件并从 0 到 100% 运行,然后递增加载的数字或“部分”并将其显示在屏幕上
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