views:

121

answers:

4

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.

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.

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.

A: 

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.

monkee
I surely have a lot more components than 14 (my current estimate for init_progress counts). Which components' initializations are reported this way?
David Hanak
A very good question. I fear I can't help you with that. But maybe I could help with finding an alternative solution.
monkee
A: 

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

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;
}
marketer
That's the download progress, not the initialization progress.
David Hanak
+1  A: 

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.

davr
A: 

The mx.preloaders.DownloadProgressBar class uses the seemingly aribtrary value of 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...?

Sly_cardinal