Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
jetstreamblue
Posts: 121
Registered: ‎01-21-2011
My Device: Z10 LE #00055
My Carrier: Telus

Progress Bar not updating

I need some help understanding how to update a progress bar.

I have an operation that runs in a loop that takes a long time to complete.  Once every loop, I update the progressBar.progress.  However, it doesn't update until the entire operation is completed.  I tried using setTimeout to cause a pause but that didn't work either.  Any ideas?

 

Pseudo code:

for (i=0;i++;i<numstufftodo)
{
    progressBar.progress = i/numstufftodo;
    setTimeout(processStuff(),1);
}

function processStuff():void
{
    // do complex calcs here
}

 

VENTURCON
For BB10: e-Mmanuel Bible Reader, e-Mmanuel Audio Bible, PM Assist
For PlayBook: e-Mmanuel Bible Reader, Business Analysis Toolbox
Please use plain text.
Developer
navikun
Posts: 43
Registered: ‎11-19-2010
My Device: Blackberry Tour
My Carrier: Verizon

Re: Progress Bar not updating

It might be because the UI thread isn't being able to update until it exits the loop (Air is single threaded).

 

You can try putting your progress bar update in a function or having your processStuff() send out events you can capture to have it update. I know the events would work, I am guessing on the function one. I am away from my computer and unable to test it for you :smileysad:

 

Maybe someone else will have a better way :Shifty:

Please use plain text.
Developer
UberschallSamsara
Posts: 1,026
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: Progress Bar not updating

Although your pseudocode looks like it should update the progress property as you intend, have you tried tracing out its value for each iteration through your loop, to confirm that the integer division on the right hand side is getting upgraded to a Number properly, and that your loop is not assigning a value of zero to the progress property for all of your loop iterations prior to the last iteration?

Please use plain text.
Developer
jetstreamblue
Posts: 121
Registered: ‎01-21-2011
My Device: Z10 LE #00055
My Carrier: Telus

Re: Progress Bar not updating

I've traced the progress property, and it is definitely updating as intended. If looks like what is happening is that it is running through the loop as fast as it can, while the numerous calls to processStuff() are being queued and processed. And while the queue of processStuff() is being run, the UI is not being updated, so in the end, it just shows complete without intermediate updates.
VENTURCON
For BB10: e-Mmanuel Bible Reader, e-Mmanuel Audio Bible, PM Assist
For PlayBook: e-Mmanuel Bible Reader, Business Analysis Toolbox
Please use plain text.
Developer
UberschallSamsara
Posts: 1,026
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: Progress Bar not updating

So does the task just run so fast that the user doesn't really need to see a progress bar?  Could there be cases where it will run a lot slower than it has done in your testing so far?

Please use plain text.
Developer
jetstreamblue
Posts: 121
Registered: ‎01-21-2011
My Device: Z10 LE #00055
My Carrier: Telus

Re: Progress Bar not updating

The task runs for several seconds during which the UI freezes.

Here is what I think is happening:

1) For loop runs, calling the task function many times as it loops through, and also updating the progress as it goes.  However, UI does not update during this time.

2) For loop ends, but the task functions are still queued to run, meanwhile, progress is already set to 1 because loop is done, but UI is still not updated.

3) Now the task functions that were called are executed one by one, meanwhile the UI is frozen.

4) The tasks complete, and the UI is finally updated, the progress bar jumps to full.

 

I think what I need is some sort of event driven way to not execute the next iteration of the loop until the task function called during that loop is finished executing.

VENTURCON
For BB10: e-Mmanuel Bible Reader, e-Mmanuel Audio Bible, PM Assist
For PlayBook: e-Mmanuel Bible Reader, Business Analysis Toolbox
Please use plain text.
Developer
UberschallSamsara
Posts: 1,026
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: Progress Bar not updating

Maybe you could post your code (or ideally a very stripped down version of it that still demonstrates the problem)?

Please use plain text.
Developer
UberschallSamsara
Posts: 1,026
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: Progress Bar not updating

BTW, one other thing: in your pseudocode, your setTimeout() call is doing a function invocation (of the "processStuff" function), *not* passing the function to setTimeout() as a closure, as it is supposed to:

 

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#setTimeo...

 

" Do not include quotation marks or parentheses, and do not specify parameters of the function to call. For example, use functionName, not functionName() orfunctionName(param)."

 

If you are including the call operator (i.e. the parens) after your function name, you are actually passing the return value of your processStuff() function to setTimeout() as a function name, which is highly unlikely to be what you intend.

Please use plain text.