如何确定来自预加载器的“initProgress”事件的总数?

时间:2021-07-14 10:13:46

The flash preloader emits FlexEvent.INIT_PROGRESS events to signal the progress of the flash application initialization. However, the number of times this event is dispatched depends on the application itself.

Flash预加载器会发出FlexEvent.INIT_PROGRESS事件,以指示Flash应用程序初始化的进度。但是,调度此事件的次数取决于应用程序本身。

I am trying to determine this number, but I couldn't find an answer in the Flex documentation, so right now I resort to experimentation. To make it worse, it appears to me that this number varies from time to time, even if the flash file is unmodified.

我试图确定这个数字,但我在Flex文档中找不到答案,所以现在我求助于实验。更糟糕的是,在我看来,即使Flash文件未经修改,此数字也会不时变化。

Is there a programmatic way to give at least an estimate on this value?

是否有一种编程方式至少对此值进行估算?

Edit: I'm using this information to display a progress bar in the preloader. Actually, I display two, one while downloading the program, and a second one while initializing it.

编辑:我正在使用此信息在预加载器中显示进度条。实际上,我在下载程序时显示两个,第二个在初始化时显示。

4 个解决方案

#1


Don't worry about the total number too much, in my experience this should happen so quickly that it's not necessary to be completely accurate. If you do a few tests, and find that it counts up to about 14, then just manually set your progress bar to have a maximum of say 20. The users will still see the bar filling up quickly, since it's not onscreen for very long, nobody cares if it's completely accurate.

不要太担心总数,根据我的经验,这应该发生得太快,以至于没有必要完全准确。如果你进行了一些测试,并发现它最多可以计算到14,那么只需手动设置你的进度条,最多可以说20个。用户仍然可以看到快速填充,因为它不会长时间在屏幕上,没有人关心它是否完全准确。

#2


The mx.preloaders.DownloadProgressBar class uses the seemingly aribtrary value of 12:

mx.preloaders.DownloadProgressBar类使用看似无穷的12值:

private var _initProgressTotal:uint = 12;

// [...]

protected function initProgressHandler(event:Event):void
{
    // [...]

    var loaded:Number = 100 * _initProgressCount /
    (_initProgressTotal - _displayStartCount);

    // [...]
}

I don't know where they get that value, but it seems to work well enough for Adobe...?

我不知道他们从哪里获得这个价值,但它似乎对Adobe来说效果不错......?

#3


Maybe that Event gets fired everytime a Component gets initialized?

每次组件初始化时,可能会触发事件?

Maybe it helps if you tell us, what exactly you want to do. We could try to find an alternative solution.

如果你告诉我们你想做什么,也许会有所帮助。我们可以尝试寻找替代解决方案。

#4


You should base your progress bar on the bytesLoaded / bytesTotal, not on the number of times the handler is called.

您应该将进度条基于bytesLoaded / bytesTotal,而不是基于调用处理程序的次数。

For example:

preloader.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onPreloaderProgress);

Then, in your handler, do something like this:

然后,在您的处理程序中,执行以下操作:

function onPreloaderProgress(e:ProgressEvent):void
{
    progress = e.bytesLoaded / e.bytesTotal;
}

#1


Don't worry about the total number too much, in my experience this should happen so quickly that it's not necessary to be completely accurate. If you do a few tests, and find that it counts up to about 14, then just manually set your progress bar to have a maximum of say 20. The users will still see the bar filling up quickly, since it's not onscreen for very long, nobody cares if it's completely accurate.

不要太担心总数,根据我的经验,这应该发生得太快,以至于没有必要完全准确。如果你进行了一些测试,并发现它最多可以计算到14,那么只需手动设置你的进度条,最多可以说20个。用户仍然可以看到快速填充,因为它不会长时间在屏幕上,没有人关心它是否完全准确。

#2


The mx.preloaders.DownloadProgressBar class uses the seemingly aribtrary value of 12:

mx.preloaders.DownloadProgressBar类使用看似无穷的12值:

private var _initProgressTotal:uint = 12;

// [...]

protected function initProgressHandler(event:Event):void
{
    // [...]

    var loaded:Number = 100 * _initProgressCount /
    (_initProgressTotal - _displayStartCount);

    // [...]
}

I don't know where they get that value, but it seems to work well enough for Adobe...?

我不知道他们从哪里获得这个价值,但它似乎对Adobe来说效果不错......?

#3


Maybe that Event gets fired everytime a Component gets initialized?

每次组件初始化时,可能会触发事件?

Maybe it helps if you tell us, what exactly you want to do. We could try to find an alternative solution.

如果你告诉我们你想做什么,也许会有所帮助。我们可以尝试寻找替代解决方案。

#4


You should base your progress bar on the bytesLoaded / bytesTotal, not on the number of times the handler is called.

您应该将进度条基于bytesLoaded / bytesTotal,而不是基于调用处理程序的次数。

For example:

preloader.loaderInfo.addEventListener(ProgressEvent.PROGRESS, onPreloaderProgress);

Then, in your handler, do something like this:

然后,在您的处理程序中,执行以下操作:

function onPreloaderProgress(e:ProgressEvent):void
{
    progress = e.bytesLoaded / e.bytesTotal;
}