So I tried this pattern:

private function onClickSave(event:Event):void {

  CursorManager.setBusyCursor();
   var generatePDF:Function = function(e:Event):void {
                    ....
                      savePDF(bytes);
                };

                 // Delay start so cursor can display
                var timer:Timer = new Timer(1, 1);
                timer.addEventListener(TimerEvent.TIMER, generatePDF);
                timer.start();
}

private function savePDF(pdfBinary:ByteArray):void {
                var fileRef:FileReference = new FileReference();
                fileRef.save(pdfBinary,"MyReport.pdf");
            }

But then of course I get the security error below from savePDF:

Error: Error #2176: Certain actions, such as those that display a pop-up
window, may only be invoked upon user interaction, for example by a mouse
click or button press.
    at flash.net::FileReference/_save()

Any good ideas for displaying a busy cursor or indeterminate progress bar
while doing a long-running synchronous operation?

On Wed, Nov 11, 2009 at 9:59 AM, Richard Rodseth <rrods...@gmail.com> wrote:

> Thanks. Yes, I wasn't expecting to show dynamically-updating progress
> during the synchronous operation. Just wanted to pop up something (or change
> the cursor) before, and remove it after. I'll take a closer look at the
> AlivePDF docs.
>
>
> On Wed, Nov 11, 2009 at 6:24 AM, ag_rcuren 
> <robert.vancuren...@gmail.com>wrote:
>
>>
>>
>> I am not fully sure how AlivePDF works because I have never used it but I
>> thought that it could be done asynchronously because I saw a complete event
>> in the documentation that reads:
>> "Dispatched when PDF has been generated and available. The save() method
>> generate this event"
>>
>> That to me says that it can be generated asynchronously but like I said I
>> really dont know.
>>
>> As far as showing progress during a synchronous call it is not possible.
>> This is because the synchronous call does not return until it is done and
>> thus the UI will never get a chance to update during the process.
>>
>> If you want to show something before that is possible. You could use a
>> timer or you may want to look at the callLater method of displayObject as
>> this will wait one frame before calling the method you want. This would
>> allow you to show say a pop up or something so they user could at least see
>> something.
>>
>>
>> --- In flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>, Richard
>> Rodseth <rrods...@...> wrote:
>> >
>> > What's a good way to display progress or a busy cursor for a potentially
>> > long-running, but synchronous operation (in my case generating a PDF
>> using
>> > AlivePDF) ?
>> >
>> > As noted here, CursorManager.setBusyCursor doesn't display the cursor
>> until
>> > there is no code running, and PopupManager seems to act similarly.
>> >
>> > Defer initiation of the operation using a timer?
>> >
>>
>>  
>>
>
>

Reply via email to