PDA

View Full Version : ProgressBar on intensive calculation function


Jim Freer
10-03-2007, 11:32 PM
I have a function to convert comma delimited data to an XML object. In addition to downloading a CSV file, I have provided an option to paste text into a TextArea control and press a button to perform a conversion. If the text is large it can take a few seconds to run and therefore I would like to show a ProgressBar for visual feedback.

Unfortunately I haven’t been able to come up a simple scheme that allows the ProgressBar to update while the conversion function is processing. (Old Visual Basic had a DoEvents function to handle this situation.)

I am convinced I can come up with a way to do this by slicing up the conversion process but it will end up being slower. Before I embark on that I was hoping to get some advice on how to do this. Maybe I’m not using the ProgressBar properly?

I set the ProgressBar’s mode property to “manual” and I call its setProgress function. I have tried it from a timer event, turned the function into a class that implements IEventDispatcher and dispatch events and even call setProgress directly from the function. Along with those I’ve tried the validateNow() function.

dr_zeus
10-05-2007, 07:11 PM
If you have a very long operation where you need to show a progress bar or something else, you should break up each iteration or two using an ENTER_FRAME event. Flash Player provides no way for you to force it to redraw while you have a very long loop running.

Jim Freer
10-05-2007, 11:40 PM
I figured that’s what I needed to do. You’re to first to ever reply to my questions so extra thanks. I no longer feel invisible.

A lot of traditional web apps, where you have control over what the user gets, work well just the way it is and compared to the RIA alternative, Ajax, Flex/Flash wins in my book. In my case where the user provides the data it’s a real problem. A few hundred lines and the program looks great but a few thousand where the delay can be seconds the program look like crap. The problem is “long operations” start popping up all over.

Coming up with an efficient way of dividing up the processes is extra work and will slow the original process down. It would serve Adobe well to provide a work around particularly for Flex apps.

Thanks Josh